Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Redirect Subroutine Output

by toolic (Bishop)
on Aug 26, 2009 at 18:28 UTC ( #791416=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Redirect Subroutine Output
in thread Redirect Subroutine Output

From the docs for print:

Note that if you're storing FILEHANDLEs in an array, or if you're using any other expression more complex than a scalar variable to retrieve it, you will have to use a block returning the filehandle value instead:
I believe the braces define a block of code, and I believe $_[0] qualifies as an 'expression more complex than a scalar variable'. If you refactor the sub like this, then the braces around the FILEHANDLE are not needed:
use warnings; use strict; sub print_to { my ($fh, $str) = @_; print $fh $str; } print_to (*STDOUT, "test stdout"); print_to (*STDERR, "test stderr");


Comment on Re^3: Redirect Subroutine Output
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2015-07-03 17:37 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 (54 votes), past polls