Welcome to the Monastery | |
PerlMonks |
Re: What script is this, and where is it? (Re: who am I?)by AZed (Monk) |
on Sep 24, 2008 at 22:21 UTC ( [id://713513]=note: print w/replies, xml ) | Need Help?? |
All of those mechanisms break if the script is being called by a symlink, and particularly so if nested symlinks are involved. You need to readlink($0) if (-l $0) first, and then check, and even then, it won't give you the same output as FindBin::RealBin. Create the following directory structure in /var/tmp. Set up directories as follows (you'll need root for /usr/local/bin, so feel free to make the last step anywhere else in your path that you'd like): Now take the following code and put it in /var/tmp/mydir/myname.pl:
Symlink /var/tmp/symdir/myname.pl to /usr/local/bin/myname (or somewhere else on your path, if you can't or don't want to tamper with a system directory). Run 'myname'. You get:
Only FindBin correctly points you to the correct data directory location. Frankly, even without symlink forests, FindBin is more readable, though.
In Section
Seekers of Perl Wisdom
|
|