Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: using chdir($variable_name) to change directory

by Anonymous Monk
on Jul 05, 2011 at 11:32 UTC ( [id://912800]=note: print w/replies, xml ) Need Help??


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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://912800]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-23 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found