Don't ask to ask, just ask | |
PerlMonks |
Re^2: Detecting if a folder is a symbolic link (tricky)by tye (Sage) |
on Mar 17, 2006 at 23:46 UTC ( [id://537614]=note: print w/replies, xml ) | Need Help?? |
You can't do if (-d $file && -l _). That will always return false. True. You must reverse that: if (-l $file && -d _). Actually, that also always returns a false value. The cached lstat results did not follow the symbolic link and so doesn't know anything about what (if anything) it links to. If you want to check for "X is a (symbolic) link to a directory", then you can't avoid doing [l]stat twice (well, lstat once and stat once). There certainly are cases where you can "cheat" (or "be efficient"). Perhaps you were thinking of a very common case, for example:
That does work and does require that you do the -l part first. - tye
In Section
Seekers of Perl Wisdom
|
|