good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
(tye)Re: FindBin is broken (RE: How do I get the full path to the script executing?)by tye (Sage) |
on Feb 10, 2001 at 00:09 UTC ( [id://57466]=note: print w/replies, xml ) | Need Help?? |
I tried to come up with a situation like you described where FindBin.pm would work but rel2abs($0) wouldn't. The only case I found was pretty strange and, IMHO, just shows more ways in which FindBin.pm is broken. If you happen to be chdir()ed into a directory that is in your $ENV{PATH} and do "perl subdir/script" and subdir/script does a BEGIN { chdir "/tmp" } before you can do your rel2abs($0), then rel2abs($0) will be wrong (returning "/tmp/subdir/script"). But FindBin.pm will see the "/" and assume that $ENV{PATH} doesn't need to be searched (which makes sense), but then will find that "./subdir/script" doesn't exist and so will change its mind. Then it will search $ENV{PATH} and will stop at the first path that actually contains a "subdir/script" in it. If that place also happens to be the directory that you happened to be in before the super-early chdir(), then FindBin.pm will have found, by accident, the correct path to the script. Personally I'd rather have FindBin.pm never search $ENV{PATH} and have it die "You chdir()ed too early" if ! -e $0 so that such strangeness could be detected rather than returning whatever it finds which might be right or might be wrong. That test isn't completely foolproof, but the ways to fool it are even more bizarre. - tye (but my friends call me "Tye")
In Section
Seekers of Perl Wisdom
|
|