P is for Practical | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Merely using Cwd and get_cwd() isn't going to cut the mustard -- mainly because you can invoke a script from directories other than your current working directory. Use abs_path() instead (or fast_abs_path()):
Note that abs_path() will also resolve chains of soft links, so if that's not what you want you might use rel2abs($0) from File::Spec, or you will have to back up a bit and manipulate $0 directly, possibly with get_cwd() and File::Spec for generating the cannonical path. And in any of these cases, use File::Spec for slicing and dicing pathnames. You can also just simply use FindBin, except that certain people might fuss at you for reasons such as these. You might also find these nodes of interest, from Q&A: Matt In reply to Re: Find the full path of the script at run time
by mojotoad
|
|