Syntactic Confectionery Delight | |
PerlMonks |
Re: Re: Re: Find the full path of the script at run timeby bart (Canon) |
on Mar 13, 2003 at 10:56 UTC ( [id://242644]=note: print w/replies, xml ) | Need Help?? |
Actually FindBin is broken in more than just this way. I've had cases where scripts that had limited permissions (CGI), where FindBin just died. It looks like it tries to verify the existence of the path it found, occasionally ending up in directories where it has no visiting rights. I'm not sure that is indeed what it does, — if so, it's likely File::Spec that is to blame; but this situation makes it useless for situations where it would be most useful.
Anyway, to answer your question: yes, $0 would be set to ..\..\script.pl. That's where tye's solution, rel2abs, would again come to the rescue. A demo of a full solution, as tye merely mentioned the function name:
update: Oh dear, it doesn't. The double dots are still in the created path. For Unix, that is the safest, as you never know which "directory" is actually just a link to another directory, so by following "foo/.." you could end up in an entirely different directory from where you started from. It doesn't look as neat, but it works just as well.
In Section
Seekers of Perl Wisdom
|
|