abubacker has asked for the wisdom of the Perl Monks concerning the following question:

Dear all
Most of the file test operator accepts both file names and handler
but why -l says error when I gave the file handler as its operand
but it accepts filename

for ex : print "works " if ( -l FH ) ; # not working print "works " if ( -l "name_of_the_file" ) # works

Please help me out!

Replies are listed 'Best First'.
Re: -l file test operator
by ikegami (Patriarch) on Aug 20, 2009 at 06:31 UTC
    You can't have a file handle to a symbolic link*, so -l is always false for a file handle. The warning is letting you know you're doing something that doesn't make sense.

    * — They're "read" using readlink.

Re: -l file test operator
by Anonymous Monk on Aug 20, 2009 at 06:25 UTC
      The error message is "Use of -l on filehandle $fh". It's a non-fatal error (aka warning). -l $fh returns undef with $! set to "Inappropriate ioctl for device" on Linux.
        oh ikegami, abubacker is supposed to respond, so he can get in the habit ...