⭐ in reply to How do I print formatted text to a scalar instead of a filehandle?
Since Perl 5.8.0 you can open a filehandle for writing to a scalar. Then, if you make that filehandle the default, writes will go there.
Content of $output:my %hash = (one => 1, two => 2, three => 3); my $output; open FH, '>', \$output; my $old_fh = select(FH); my $key; foreach $key (keys %hash) { write; } select ($old_fh); print $output; format FH = @<<<<<<<<< @## $key, $hash{$key} .
three 3 one 1 two 2
Unfortunately, this doesn't seem to work with localized filehandles.
|
|---|