in reply to How to redirect STDOUT to an array (not executing program)

Depending on how far you want to go with using CPAN modules, it is fairly easy to redirect STDOUT to a scalar, see open:
my $var; close STDOUT; open(STDOUT, '>', \$var) || die "Unable to open STDOUT: $!"; print "Hollow World\n"; print "And another\n"; close (STDOUT); my @data = split "\n", $var; local $" = '|'; print STDERR "<@data>\n";
Beware that this does work for STDOUT in child processes.

Replies are listed 'Best First'.
Re^2: How to redirect STDOUT to an array (not executing program)
by rapide (Beadle) on Jan 18, 2009 at 12:57 UTC
    Great! Your example was exactly what I was looking for. Thank you