Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by davido (Cardinal)
on Oct 02, 2003 at 03:55 UTC ( [id://295808]=note: print w/replies, xml ) Need Help??


in reply to How do I treat a string like a filehandle?

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://295808]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-23 18:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found