Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: write from filehandle to variable

by chibiryuu (Beadle)
on Nov 21, 2005 at 20:20 UTC ( #510548=note: print w/replies, xml ) Need Help??

in reply to Re^2: write from filehandle to variable
in thread write from filehandle to variable

use if $] < 5.008, 'IO::Scalar'; # IO::Scalar is needed in pre-5.8 Perl my $var = ''; # this is the variable we will be writing to or readi +ng from my $fh; # this is a filehandle, reads and writes will go to $ +var if ($] < 5.008) {$fh = new IO::Scalar \$var} else {open $fh, '+<', \$var} $fh or die "can't get filehandle for \$var: $!"; print $fh "These print statements will\n"; print $fh "be appended to \$var.\n"; seek $fh, 0, 0; # reading and writing <$fh> will seek in $var. my $var1 = <$fh>; my $var2 = <$fh>; print $var1; # print "These print statements will\n" print $var2; # print "be appended to \$var.\n"

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2018-11-16 16:36 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (199 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!