Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Answer: How do I treat a string like a filehandle?

by davido (Archbishop)
on Oct 02, 2003 at 03:55 UTC ( #295808=categorized answer: print w/replies, xml ) Need Help??

Q&A > strings > How do I treat a string like a filehandle? - Answer contributed by davido

You may open a file handle to "in memory" files (ie, scalars... or strings), if you're using a new enough version of Perl. I believe this feature was introduced with 5.8.0.

Per perlfunc:open; 'File handles can be opened to "in memory" files held in Perl scalars via:
open( $fh, '>', \$variable) || die ....
Though if you try to re-open STDOUT or STDERR as an "in memory" file, you have to close it first.'

Another example provided in the POD is:

open(MEMORY, '>', \$var) or die "Can't open memory file: $!\n"; print MEMORY "foo!\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
choroba mornings back
[Corion]: Hi choroba!
[Corion]: And Discipulus!
Corion arrived back from London. Always nice to meet people again, even if it's just once per year.
[Corion]: Also, dk contributed some cool stuff to App::ShaderToy, like menu settings and real fullscreen, eliminating many of my #TO-DO comments ;)
[Corion]: I hope you spent the four days well without me online ;-D

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2016-12-06 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (101 votes). Check out past polls.