drewbie has asked for the wisdom of the Perl Monks concerning the following question:
my $content; tie *STDOUT, 'IO::Scalar', \$content; do $file; untie *STDOUT; return $content;
What was happening is that I got the proper data back from the called code, but I couldn't print to STDOUT! If I printed $content to STDERR the error log showed the proper putput. It seems obvious to me now that STDOUT was somehow either getting closed or was not getting untied. Now I'm using
and it works 100% as expected. But I don't understand why the old approach did not work. This is a web app and the browser got nothing but some empty headers I believe Apache or CGI.pm was adding. Any thoughts?tie(*CAPTURE, 'IO::Scalar', \$content); select(CAPTURE); $| = 1; do $file; select(STDOUT); untie(*CAPTURE); return $content;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capturing STDOUT
by rdfield (Priest) on Nov 05, 2002 at 09:41 UTC | |
by drewbie (Chaplain) on Nov 05, 2002 at 14:45 UTC |