I disagree. The easiest way to save the current directory and return to it later is File::chdir, which lets you change directories through a localized variable. Example:
use File::chdir; print $CWD; # now cd and show me a directory listing { local(@CWD,$CWD); push @CWD,'subdir'; print $CWD; print join("\n", glob '*'); } # now we're back where we started. We'll do a listing to show. print $CWD; print join("\n", glob '*');
The imported variable $CWD always holds the full path, so you can also just store it to a variable and restore the value later, even mixing things with chdir.
use File::chdir; my $wd = $CWD; chdir('subdir'); # do some work. $CWD = $wd; # return to saved dir.
Now, that may not be the best way, but I'd vote for it as easiest. :-)
In reply to Re^2: Testing the current directory with Cwd and File::Spec
by radiantmatrix
in thread Testing the current directory with Cwd and File::Spec
by xdg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |