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 scalar(string).
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
http://java.sun.com/j2se/1.4.2/docs/api/java/io/ByteArrayInputStream.html
and ByteArrayOutputStream
http://java.sun.com/j2se/1.4.2/docs/api/java/io/ByteArrayOutputStream.html
in Java.
Does such a Module exist? I tried to search CPAN
but didn't really know what search terms to use.
BugBear
Looks like IO::String is close to what you want.
> It is quite common for modules to be able to handle
> 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 scalar(string).
>
> A readonly version of this would present
> the string as a readable FileHandle,
my $yourstring = "hello, world";
open my $fh, '<', \$yourstring or ...
> and a writeonly
> version would allow writing/printing to a string,
> which could be picked up later.
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:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html
Well, that couldn't be much easier to use, or harder to find!
It *never* occurred to me that it would be that easy, and (thus)
I never looked in perldoc -f open.
Thanks for the (perfect) reply.
BugBear