Keep It Simple, Stupid | |
PerlMonks |
Re: Surprising behavior of Cwd module on Unix with symlinksby ELISHEVA (Prior) |
on Feb 08, 2011 at 06:15 UTC ( [id://886890]=note: print w/replies, xml ) | Need Help?? |
The most portable solution would be to avoid the use of relative paths (and pwd/cwd) altogether. If you really, truly need to go forward with a particular path, you can avoid the "auto-resolving link" problem altogether by constructing the fully qualified path and using that in your program. In general, littering your code with relative paths and dependencies on the current working directory is not a good idea. There are several problems that can result:
See File::Spec for a portable way to attach relative paths to a fully qualified starting path. About the only situation where I can see a genuine use for cwd is (a) start-up situations (b) incoming information (but here lie security risks which is why taint mode doesn't let you use them) and (c) an occasional piece of software that actually requires itself to be run with a particular directory or kind of directory as "current". Most applications do accept fully qualified paths even if the documentation examples only illustrate relative path parameters for convenience In start-up/incoming information situations you may want to find certain files based on the starting directory of a user. However, in my own code, I immediately convert that to a fully qualified path and from there on in use fully qualified paths in the code.
In Section
Seekers of Perl Wisdom
|
|