Re: Filehandle Adapter for String?
- From: John Bokma <john@xxxxxxxxxxxxxxx>
- Date: 15 Oct 2008 16:51:08 GMT
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
.
- Follow-Ups:
- Re: Filehandle Adapter for String?
- From: bugbear
- Re: Filehandle Adapter for String?
- References:
- Filehandle Adapter for String?
- From: bugbear
- Filehandle Adapter for String?
- Prev by Date: Re: Filehandle Adapter for String?
- Next by Date: Re: Comparing audio files
- Previous by thread: Re: Filehandle Adapter for String?
- Next by thread: Re: Filehandle Adapter for String?
- Index(es):
Relevant Pages
|