sh1tn has asked for the wisdom of the Perl Monks concerning the following question:
package cwd; use Carp; use File::Basename; use Cwd qw(realpath getcwd chdir); my $current; BEGIN { $current = getcwd; my $basename = basename $0; my $realpath = realpath $0; $realpath =~ s/$basename$//; chdir $realpath or croak "cannot chdir: $!\n"; } END { chdir $current or croak "cannot chdir: $!\n"; } 1
# /tmp/caller/CALLER # /tmp/callee/CALLEE # CALLEE content: use strict; use cwd; use Cwd; map{ print $_,$/ }glob'*'; print "\ncallee dir:", getcwd, "\n"; # CALLER content: use strict; use Cwd; print qx|/tmp/callee/CALLEE|; print "\ncaller dir:", getcwd, "\n"; # output (from `cd /tmp/caller; ./CALLER`): CALLEE callee dir:/tmp/callee caller dir:/tmp/caller
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: cwd pragma (rfc)
by japhy (Canon) on Jun 27, 2006 at 22:34 UTC | |
by ikegami (Patriarch) on Jun 27, 2006 at 23:14 UTC | |
by sh1tn (Priest) on Jun 28, 2006 at 10:25 UTC | |
by ikegami (Patriarch) on Jun 28, 2006 at 13:46 UTC | |
|
Re: cwd pragma (rfc)
by Tanktalus (Canon) on Jun 28, 2006 at 04:04 UTC |