[prog] [Perl] chdir and redirection

Jacinta Richardson jarich at perltraining.com.au
Sun Dec 10 11:45:50 UTC 2006


Chris Henderson wrote:
> 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 -

The code appears to be working perfectly for me.  Once you've run it, make sure 
you look in the code/ directory.  Perl (or any sub-process for that matter) 
cannot change the working directory (or any other aspect) of the parent process. 
  Thus, as soon as perl finishes running you'll be returned to the directory 
from which you started your program.

All the best,

	J


More information about the Programming mailing list