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 - Hacking & Hiking in Mexico

Perl help in exchange for a gift:

Relevant Pages

  • Re: understanding arrays, and their use
    ... The fourth field can be a string enclosed in quotes with either a file path, or multiple words separated by spaces. ... Now, separate a line into four groups, with whitespace separating them. ... set filehandle ...
  • Re: Filehandles Referenced with a Variable
    ... > it's a reference to a filehandle, when it's a string, naturally it ... I got rid of the quotes: ... that is just a word wrap problem. ... > filehandle, which I imagine you thought you were opening on line 16 ...
  • Re: perl interpreter output meaning?
    ... Use of uninitialized value $9 in concatenation or string at ... Usually written as the null filehandle in the angle operator ... automatically read the contents of all the files in @ARGV. ...
  • Re: Filehandle Adapter for String?
    ... the string as a readable FileHandle, ... Unless you've changed this, you can open file handles to "in memory" files held in Perl scalars via: ... I never looked in perldoc -f open. ...
  • Re: Reading text files
    ... other things that someone else will point out for you, but the main reason that your current code is so slow is that you are repeatedly concatenating substrings. ... because every time you add a little bit extra VB has to ditch the existing string and create a new one. ... Line Input #filehandle%, strBuffer ' Read line of data. ... strText = strText & strBuffer & vbCrLf ...