Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: check if a filehandle is STDOUT when using use strict;

by bart (Canon)
on Dec 31, 2012 at 11:22 UTC ( #1011043=note: print w/ replies, xml ) Need Help??


in reply to check if a filehandle is STDOUT when using use strict;

I seriously doubt if comparing to \*STDOUT will do. After all, a filehandle is a special entry in a typeglob, it's not just a plain scalar that you can compare. It's not even a reference.

But you can always use fileno, and applying the snippet of code on the page, you can do:

if(fileno($fh)==fileno(STDOUT)) { # ... }

And yes, fileno(STDOUT) is allowed by strict.

There could be a bit of a problem if $fh is a tied filehandle instead of a physical handle. In that case, fileno will return -1, which is different from the default value for STDOUT, which is 1. If you tie STDOUT too, then you're in trouble.


Comment on Re: check if a filehandle is STDOUT when using use strict;
Select or Download Code
Replies are listed 'Best First'.
Re^2: check if a filehandle is STDOUT when using use strict;
by ISAI student (Scribe) on Jan 01, 2013 at 06:56 UTC
    It's a physical handle. Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2015-07-28 09:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls