in reply to Portable in-memory files

You can hack up a tied filehandle, which is actually a scalar (there are prolly a gazillion out there):
package Scandle; sub TIEHANDLE { my ($buffer, $pos); bless [ $buffer, $pos],shift }; sub WRITE { my $self = shift; $self->PRINT($#_ ? substr($_[0],0,$_[1]) + : $_[0] ); } sub PRINT { my $self = shift; my $write = shift; if ($self->[1] != length($self->[0]){ if (length($write) > length($self->[0])-$self->[1]){ substr($self->[0],$self->[1],length($_[0])-$self->[1],''); } else { substr($self->[0],$self->[1],length($write),$write); $self->[1] += length($write); return 1; } } $self->[0] .= $write; $self->[1] = length($self->[0]) }
this should take care of most of it... emulate whatever more you need. untested.

-nuffin
zz zZ Z Z #!perl

Replies are listed 'Best First'.
Re: Portable in-memory files
by crenz (Priest) on Apr 06, 2003 at 21:32 UTC

    Thanks very much! I added

    sub CLOSE { my $self = shift; return $self->[0]; }
    so I can get at the content nicely by close()ing the handle.