Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

runrig (3385)


Just another perl hacker somewhere near Disneyland

I have this homenode [] of little consequence on Perl Monks [] that you probably have no interest in whatsoever.

I also have some modules [] on CPAN [] some of which are marginally [] more [] useful [] than others.

Journal of runrig (3385)

Thursday September 20, 2007
05:28 PM

Cwd::chdir not useless after all

[ #34498 ]
Prior to today, I always considered Cwd::chdir() rather pointless. It keeps $ENV{PWD} up to date. But if you wanted $ENV{PWD}, why not just call Cwd::cwd() (unless maybe you wanted PWD when the program started, but then you wouldn't need Cwd at all)? Well, we had this awful code:

open( FH, "pwd|" ) or die "....: $!";
my $dir = <FH>;
chomp $dir;

It was awful, but it worked, at least until we migrated this code to a system where '/foo/bar' was a symbolic link to '/foo/blah/bar' (and there was logic that depended on stuff being in '/foo/bar'). pwd in /foo/bar from the command line returned /foo/bar. But pwd from within perl returned /foo/blah/bar. Cwd::cwd() also returned /foo/blah/bar. But $ENV{PWD} returned /foo/bar. And we chdir'd a lot. So Cwd::chdir() saved us from changing some hardcoded /foo/bar's, and gave me an excuse to replace the awful code above with:

my $dir = $ENV{PWD};

And actually, the code is really just trying to recursively search directories, so I really ought to use File::Find...but that's more refactoring than I'm willing to do at this point :-)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.