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

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.

Replies are listed 'Best First'.
Re^4: In memory filehandles
by polettix (Vicar) on Jan 27, 2006 at 09:38 UTC
    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?

        The workaround with IO::File worked fine, and it doesn't require the installation of external modules in recent perls. While probably not the best for long-term production code, I find it better for example scripts that can work with the least requirement for the user.

        About open() you're right... probably. One of the thousands things I tried involved using File::Temp to get a temporary, "real-file" handle, but the readFromFileHandle() method continued to complain. I had to use the filename given back by File::Temp instead of the filehandle.

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

        Don't fool yourself.