in reply to print to data

Besides the push solution, you can also print to a filehandle that has been opened to an in-memory variable:

my $output; open my $fd, '>', \$output or die "open: $!"; ## print to the $output scalar print $fd "hello\n"; print $fd "world\n"; close $fd; ## use results print $output; __END__ hello world

--
David Serrano

Replies are listed 'Best First'.
Re^2: print to data
by imp (Priest) on Sep 06, 2006 at 12:10 UTC
    Opening scalar refs is one of my favorite newish features of perl. Keep in mind that this works for perl 5.8 and above. For earlier versions you would have to use IO::Scalar or IO::String.
Re^2: print to data
by Yoda_Oz (Sexton) on Sep 06, 2006 at 11:55 UTC
    Hue-Bond: thanks, that was a fantastic idea. it worked perfectly! cheers!