Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to Re: FindBin is broken (RE: How do I get the full path to the script executing?)
in thread How do I get the full path to the script executing?

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")

Replies are listed 'Best First'.
Re^2: FindBin is broken (RE: How do I get the full path to the script executing?)
by massa (Hermit) on Feb 18, 2009 at 01:07 UTC
    And that is why I wrote scriptname. :-)
    []s, HTH, Massa (κς,πμ,πλ)

      Then the next version of your module should have a name that starts with a capital letter and contains "::" in it (unless your module is actually a pragma and part of core, neither of which appear to be the case from here).

      - tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found