Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Answer: How do I print formatted text to a scalar instead of a filehandle?

by GrandFather (Sage)
on Jan 05, 2007 at 01:15 UTC ( #593051=categorized answer: print w/replies, xml ) Need Help??

Q&A > input and output > How do I print formatted text to a scalar instead of a filehandle? - Answer contributed by GrandFather

Writing to a scalar is a pretty good way to do it:

use strict; use warnings; my %hash = (one => 1, two => 2, three => 3); # create a format picture for use with formline format OUTPUT = @<<<<<<<<< @## $_, $hash{$_} . my $str; open OUTPUT, '>', \$str; write OUTPUT foreach sort keys %hash; close OUTPUT; print $str;

  • Comment on Answer: How do I print formatted text to a scalar instead of a filehandle?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2017-11-20 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (286 votes). Check out past polls.

    Notices?