in reply to Re^2: Virtual Filehandles..in thread Virtual Filehandles..
the module you referenced uses a temp file:
my $tmpfile = $class->{tmpfile} = '.tmp.' . $$; $FILEHANDLE = new FileHandle "$tmpfile", O_RDWR|O_CREAT or croak "$tmp +file: $!"; $class->{FILENO} = $FILEHANDLE->fileno(); $class; [download]
I didn't know it used a temp file. If I were to build the module to do this I'd use Tie::Handle and overload the writing functions.
I didn't test this or even try to compile it.
my $data = tie $fh, 'Tie::Handle::Scalar::WithoutTemp'; print $fh "Hello world"; print $$data; package Tie::Handle::Scalar::WithoutTemp; use base 'Tie::Handle'; sub TIEHANDLE { my $classname = shift; my $data; bless \ $data, $classname; } sub WRITE { my ( $self, $scalar, $length, $offset ) = @_; $$data .= substr $scalar, $offset, $length; 1; } sub PRINT { $$data .= join $,, @_[ 1 .. $#_ ]; 1; } sub PRINTF { $$data .= sprintf $_[1], @_[ 2 .. $#_ ]; 1; } [download]