in reply to using chdir($variable_name) to change directory
Relative paths are relative.
Read http://en.wikipedia.org/wiki/Path_%28computing%29
The solution, is to keep track of the starting path.
One way
use strict; ## IMPORTANT!!! use warnings; ## IMPORTANT!!! use File::Tools qw/ pushd popd /; use Cwd qw/ cwd /; ... for my $dir( @dirs ){ pushd( $dir ); print cwd(), "\n"; popd( $dir ); }
Another way
use strict; ## IMPORTANT!!! use warnings; ## IMPORTANT!!! use autodie; ## IMPORTANT!!! use Cwd qw/ cwd /; our $startingDir = cwd(); ... for my $dir( @dirs ){ chdir $dir; # autodie makes this die on error print cwd(), "\n"; chdir $startingDir; }
|
|---|