Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: Writing formatted text to a string?

by loris (Hermit)
on May 16, 2011 at 14:53 UTC ( #905093=note: print w/ replies, xml ) Need Help??

in reply to Re: Writing formatted text to a string?
in thread Writing formatted text to a string?

Just to remind myself: The backslash in open($fh, '>', \$variable) allows the filehandle to be opened to an "in memory" file held in a scalar. See open.


Here is my working example:

#!/usr/bin/perl use strict; use warnings; use English qw( -no_match_vars ); use Getopt::Long; my $in_memory; GetOptions('in_memory|i' => \$in_memory, ); my $greeting = "Hello World!"; format BLAH = Greeting: @<<<<<<<<<<<<<<<< $greeting . my $fh; my $message; if (defined($in_memory)) { open $fh, '>', \$message or die "Couldn't open for writing: $!"; } else { $fh = *STDOUT; } select($fh); $FORMAT_NAME = 'BLAH'; write(); select(STDOUT); if (defined($in_memory)) { print "Message written to in memory variable:\n"; print "$message"; close($fh); }


Comment on Re^2: Writing formatted text to a string?
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://905093]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-11-25 05:13 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (670 votes), past polls