Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: In memory filehandles

by polettix (Vicar)
on Jan 26, 2006 at 13:15 UTC ( [id://525711]=note: print w/replies, xml ) Need Help??


in reply to Re: In memory filehandles
in thread In memory filehandles

So, this basically means that there aren't any hooks to plug IO::File instead of IO::Handle where needed. As a workaround, I'm using something like this:
sub open_memory { my ($mode, $scalar_ref) = @_; open my $fh, $mode, $scalar_ref or die "open(): $!"; my $retval = IO::File->new_from_fd($fh, $mode) or die "IO::File->new_from_fd() failed"; return $retval; } ## end sub open_memory
This makes clear that in-memory filehandles aren't a real substitute for IO::String-s as I used to believe.

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

Replies are listed 'Best First'.
Re^3: In memory filehandles
by ysth (Canon) on Jan 26, 2006 at 15:39 UTC
    Or you could just use FileHandle;. Or you could push @IO::Handle::ISA, "IO::File". Or call $fh->IO::File::seek(...).

    Except for giving easy access to the per-filehandle punctuation variables, I think the whole "let's pretend filehandles are objects" thing is pretty silly.

      I generalised an actual problem I had: using in-memory filehandles with Archive::Zip. Thus, I'm stuck to passing something that a third party library likes, which basically eliminates the third solution. The second solution seems a bit overkill and not scalable, but it could come handy with proper localisation I think. The first... I'll give it a try.

      I'm also thinking about blessing the filehandle directly to IO::File, and see what happens.

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Don't fool yourself.
        You'd probably be best off just using IO::String.

        It looks to me like Archive::Zip would have the same problem with any filehandle opened with the open builtin, even disk files; is this the case?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://525711]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2024-04-19 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found