in reply to Determining indirect filehandles

Well, you probably want to test for defined eval { fileno $fh }...

$fh = \*STDIN; print "Nope\n" unless eval {fileno $fh};

It still doesn't really work, though. This must be the first example of code that doesn't work with no strict! Try this:

$fh = 'STDOUT'; print "Nope\n" unless defined eval {fileno $fh};
This prints <samp>Nope</samp> with strict (can't use string as symbol ref), but not without strict...

Replies are listed 'Best First'.
Re: Re: Determining indirect filehandles
by Masem (Monsignor) on Jan 23, 2002 at 23:27 UTC
    I would think most good programmers would not have a problem with running strict at all times, but in case they don't, the latter case can be easily resolved using:
    ref( $fh ) && defined eval { fileno $fh }
    (At least, the quick spot checks that I've done indicate this works as expected for different indirect filehandle types).

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important