Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to Re: Detecting if a folder is a symbolic link
in thread Detecting if a folder is a symbolic link

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:

if( ! -l $file && -d _ ) { } #or if( -l $file ) { ... } elsif( -d _ ) { ... } elsif( -f _ ) { ... } else { ... }

That does work and does require that you do the -l part first.

- tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://537614]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-19 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found