Chetan Patil ([EMAIL PROTECTED]) said something to this effect:
> Hello,
> We have a large code base printing header, body and footers to the STDOUT
> from the cgi scripts. Since all these are print statements, we have to go to
> extreme measures to make sure we donot print the content more than once.
> To clean things up (or at least start at it), we want to be able to trap the
> output of print to a local buffer and then selectively flush or junk based
> on the logic (for eg, if we decide to redirect at the end of the script,
> then we want to junk the buffer).
> I am looking for a quick solution which would allow me to override the
> CORE::print function and simply write to a buffer (a perl scalar). Once I am
> done with the processing, I can write out the buffer or junk it.
> Is it possible to do this? What should I be careful of?

How about selecting a different filehandle than STDOUT? For example, an
IO::String object?

IO::String is great (find it on CPAN). Here's an example:

bash$ perl -MIO::String
my $f = '';        
my $io = IO::String->new($f);
my $oldfh= select $io;
print "Hello, World!\n";
select $oldfh;
print $f;
^D
Hello, World!
bash$

Create a new IO::String object at the beginning of each script, select it, and
then you don't have to modify your print statements. Just be sure to reselect
STDOUT (or $oldfh as above).

Beware, however: IO::String seems pretty expensive (it uses tie).

(darren)

-- 
There are worse things in life than death. Have you ever spent an
evening with an insurance salesman?
-- Woody Allen

Reply via email to