Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

(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 ( #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 files

I tried to come up with a situation like you described where would work but rel2abs($0) wouldn't.

The only case I found was pretty strange and, IMHO, just shows more ways in which 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 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 will have found, by accident, the correct path to the script.

Personally I'd rather have 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://57466]
and the monks are mute...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2018-06-20 00:34 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.