Re: Filehandle Adapter for String?



bugbear <bugbear@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

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
.