At least part of the problem is this line:
Code:
system 'ls -al $home';
Single quotes mean to pass a literal string, but since $home is a variable which you have set in your program, you probably want to have it expanded before it gets passed to ls. Change this line to:
Code:
system "ls -al $home";
By the way, you can get the value of envionrment variables from the %ENV hash. HOME (case sensitive!) is almost always defined in the environment, so you might as well take it from there. For example:
Code:
chdir $ENV{HOME} or die "cannot change directory: $!";
So, all in all, I'd re-write like this:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
my $dir = $ENV{HOME} . "/coding";
chdir $dir or die "cannot change directory to $dir: $!";
open STDOUT, ">ls.out" or die "can't write to ls.out: $!";
open STDERR, ">ls.err" or die "can't write to ls.err: $!";
system "ls -al $dir";