in reply to Re^2: Need Help: Capture Print Outputs from a Function
in thread Need Help: Capture Print Outputs from a Function
I prefer
over{ open local *STDOUT, '>', \$buf; ... }
open TEMP, '>', \$buf; my $old_select = select(TEMP); ... select($old_select);
since the former restores STDOUT even in the case of exceptions. The former, however, doesn't work if someone has previously called select. I guess the comprehensive solution would be:
{ my $old_select = select(); my $handle = on_release { select($old_select); }; open local *STDOUT, '>', \$buf; select(STDOUT); ... }
It even handles exceptions thrown by signal handlers.
Updated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Need Help: Capture Print Outputs from a Function
by BrowserUk (Patriarch) on May 03, 2006 at 08:30 UTC | |
by ikegami (Patriarch) on May 03, 2006 at 16:34 UTC |