in reply to Appending print to a variable

If your using 5.8, you could also use an "in memory file". See perlfunc:open pod from 5.8 for details, but basically this involves closing STDOUT and then re-opening it to a scalar ref.

close STDOUT; open STDOUT, '>', \my $buffer or die $!; print ....; # This will append the output to $buffer

Alternatively, you could open another filehandle to a scalar and then select that filehandle as the default output stream prior to your print statements and select back when your ready to print output to STDOUT.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller