smile4me has asked for the wisdom of the Perl Monks concerning the following question:
Is there a way to control when print() actually goes to STDOUT? I have a LOTS of legacy code that has embedded print statements. I'd like to rearrange when things print without having to rewrite all the subroutines. For example,
$str = q[new text]; $str .= sample( qw(1 2 3) ); $str .= q[more new text]; print_now( "$str \n" ); sub sample { print q[sample(): ], @_, "\n"; } sub print_now { say @_; ## or print $FH @_; }
Is there some trick to prevent the text in sample() from print'ing first? Can I redirect STDOUT to a variable in the code?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to control/redirect print()
by GrandFather (Saint) on Apr 03, 2011 at 01:23 UTC | |
|
Re: how to control/redirect print()
by wind (Priest) on Apr 03, 2011 at 02:38 UTC | |
|
Re: how to control/redirect print()
by Marshall (Canon) on Apr 03, 2011 at 06:09 UTC | |
|
Re: how to control/redirect print()
by hesco (Deacon) on Apr 03, 2011 at 01:47 UTC | |
|
Re: how to control/redirect print()
by smile4me (Beadle) on Apr 04, 2011 at 18:43 UTC |