[Pdx-pm] Emulate a file in memory?

Eric Wilhelm ewilhelm at sbcglobal.net
Fri Oct 1 13:22:05 CDT 2004


# The following was supposedly scribed by
# Roderick A. Anderson
# on Friday 01 October 2004 01:02 pm:

>Is is possible, in Perl, to emulate a file in memory?  Open it, read
>from, write to etc. then save to disk when closed?

I was recently trying to find something like python's StringIO, which 
lets a string be a filehandle.  However, I suspect that this is done 
in StringIO by creating a tempfile and opening it.  That seemed to be 
the easiest way to handle it in Perl too.

It might be possible to overload the <> operator, but I'm not sure 
about print(), read(), seek(), and etc.  Furthermore, if you are 
using this magic filehandle with SQLite, it is likely performing 
these operations in C, so your perl overloads wouldn't work.

I take it that you're trying to do this without a tempfile for 
security reasons?  If that's the case, the simplest answer would be 
to use a tempfile with appropriate permissions.

--Eric
-- 
"I've often gotten the feeling that the only people who have learned 
from computer assisted instruction are the authors."
                                        --Ben Schneiderman



More information about the Pdx-pm-list mailing list