[Pdx-pm] Emulate a file in memory?
Eric Wilhelm
ewilhelm at sbcglobal.net
Fri Oct 1 14:37:43 CDT 2004
# The following was supposedly scribed by
# Colin Kuskie
# on Friday 01 October 2004 01:37 pm:
>> I was recently trying to find something like python's StringIO,
>> which lets a string be a filehandle.
>
>You mean like IO::String?
>
>http://search.cpan.org/~gaas/IO-String-1.05/
heh. Yeah, exactly like that except using the builtin <>,
seek(HANDLE, $off, $whence), and such-like syntax.
So, this isn't really what I was looking for, but it's manpage did
clue me in on the fact that perl has native support for what I was
wanting since 5.8! A look at my 5.8.3 perldoc -f open has all of the
fun details.
perl -e '$a = "foo
bar
baz";
open(A, "<", \$a) or die;
seek(A, 0,0);
read(A, $b, 7);
print "$b\n";
seek(A, 1,0);
read(A, $b, 2);
print "$b!\n";'
So, you've found my solution (and maybe the guts that implement this
are magic enough to work with SQLite too.) If so, that might solve
Rod's problem as well (provided that he has 5.8 or better.)
Thanks,
Eric
--
"It is a mistake to allow any mechanical object to realize that you
are in a hurry."
--Ralph's Observation
More information about the Pdx-pm-list
mailing list