Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Redirect subroutine output

by fil309 (Initiate)
on Jan 06, 2014 at 08:45 UTC ( #1069473=perlquestion: print w/ replies, xml ) Need Help??
fil309 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, How can I redirect a subroutine output to a file without changing the subroutine? Thanks

Comment on Redirect subroutine output
Re: Redirect subroutine output
by syphilis (Canon) on Jan 06, 2014 at 08:54 UTC
    Not sure if this counts as a "redirection to file":
    use strict; use warnings; open WR, '>', 'file.out' or die "Can't open WR for writing: $!"; print WR foo(); close WR or die "Can't close WR: $!"; sub foo { return 'FOO'; }
    Cheers,
    Rob
Re: Redirect subroutine output
by Anonymous Monk on Jan 06, 2014 at 09:16 UTC
    write a wrapper-sub of same name and use select to set the default filehandle for output.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-10-25 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (147 votes), past polls