http://www.perlmonks.org?node_id=302102


in reply to Re: in memory files in 5.6.1
in thread in memory files in 5.6.1

Thanks Liz

update: Thanks hanenkamp

IO::stringy looks useful, but as far as I can tell an stringy object can't be treated exactly like a file handle.

For example I have to invoke the print method of the object instead of printing to a file handle

Replies are listed 'Best First'.
Re: Re: Re: in memory files in 5.6.1
by hanenkamp (Pilgrim) on Oct 25, 2003 at 20:33 UTC

    Not true, this should work:

    use IO::Scalar; my $fh = IO::Scalar->new; print $fh "foo\n"; # Rather than $fh->print ... # or, if you prefer select $fh; print "bar\n";

    This works through the magic of a tied file handle. See perltie for details on tying a file handle.

      Hi hanenkamp,
      please do you have an idea to how handle these kind of "InMemoryfile" to put this on a local drive or to a webserver via HTTP::DAV of (S)FTP ?
      The transfer programs allways want to have a filename instead a filehandle.

      Regards
      WolliK
        how handle these kind of "InMemoryfile" to put this on a local drive

        Well, just use a plain file instead!

        or to a webserver via HTTP::DAV of (S)FTP ? The transfer programs allways want to have a filename instead a filehandle.

        HTTP::DAV implements WebDAV, which is, as the name suggests, an extension to HTTP. HTTP does not know anything about files. So a sane DAV client should be able to upload arbitary data, not just files. And in fact, HTTP::DAV documents for the put method:

        One can upload/put a string by passing a reference to a scalar in the -local parameter.

        Of course, to access the scalar behind IO::Scalar, you need to pass a reference to a scalar to the constructor IO::Scalar->new(), see IO::Scalar. BTW: You would pass the same reference to HTTP::DAV's put() method.

        Net::SFTP implements open, read, write, close. No need to mess with in-memory files, but of course, you could write the scalar used to store the in-memory file using Net::SFTP's write method.

        Net::FTP accepts a file name or a file handle for put(), so you should be able to pass the IO::Scalar instance to put().

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)