[prog] [Perl] chdir and redirection
Chris Henderson
hendersochris at gmail.com
Sun Dec 10 10:22:30 UTC 2006
Hi list,
I'm trying to write a simple Perl code which will [1] change directory to
/home/me/code, and [2] redirect the "ls" output to files.
It's not doing either one of them and just gives me back the shell. Here's
the code -
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
my $dir = $ENV{HOME} . "/code";
chdir "$dir" or die "cannot change directory: $!";
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";
Thanks.
More information about the Programming
mailing list