Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Filehandle Adapter for String?
October 15, 2008, 4:02 pm
rate this thread
files, or filehandles, but not strings.
In order to ease some of the uses I have for
such modules, in an age where a 1 Mb scalar
is reasonable, I would quite like to have a class/module
that Implements FileHandle, but is (really)
A readonly version of this would present
the string as a readable FileHandle, and a writeonly
version would allow writing/printing to a string,
which could be picked up later.
This is by close analogy with ByteArrayInputStream
Does such a Module exist? I tried to search CPAN
but didn't really know what search terms to use.
Re: Filehandle Adapter for String?
my $yourstring = "hello, world";
open my $fh, '<', $yourstring or ...
open my $fh, '>', $yourstring or ...
Since v5.8.0, perl has built using PerlIO by default. Unless
you've changed this (i.e. Configure -Uuseperlio), you can open
file handles to "in memory" files held in Perl scalars via:
perldoc -f open
John http://johnbokma.com/ - Hacking & Hiking in Mexico
Perl help in exchange for a gift: