On Wednesday 03 May 2006 03:29 am, D. Bolliger wrote: > tom arnall am Sonntag, 30. April 2006 22.57: > [...] > > > OK, the above stuff is all good. And now I have another question. The > > following code: > > > > #!/usr/bin/perl -w > > use strict; > > use Tie::Scalar; > > use DB_File; > > > > my ($f,@f,%f); > > > > tie %f, "DB_File", "file.txt" ; > > $f{'a'}='aaaa'; > > untie %f; > > %f = (); > > tie %f, "DB_File", "file.txt" ; > > @f = %f; > > print " > > @f"; > > > > tie $f,"Tie::StdScalar","scalar.txt","\$f"; > > $f = 'a'; > > untie $f; > > $f = ''; > > tie $f,"Tie::StdScalar","scalar.txt","\$f"; > > print " > > $f > > "; > > > > > > produces: > > > > a aaaa > > scalar.txt > > Hello tom > > Since I'm not enough experienced with tie'ing, I can only provide a very > basic > > and hopefully correct answer: > > shouldn't the second line be 'a', i.e., shouldn't 'StdScalar' work along > > the lines of the code handling the tied hash variable? > > When you look at the source of the Tie::StdScalar package, you can see that > the TIESCALAR method just blesses a reference to the string 'scalar.txt' to > the Tie::StdScalar class, FETCH gets the string, and STORE sets it. > (further arguments, as "\$f" - the same as '$f' btw - above, are ignored). > > The class does not know that you want to treat 'scalar.txt' as a filename, > and therefore no persistent storage is involved, and thus the change done > by $f = 'a' is lost after untie'ing. > > > if this is not true, > > is there a module that does work similarly to 'DB_File', i.e., one that > > enables tie-ing a text file to a scalar? > > I don't know. Maybe you want to look at Tie::File to access the lines of a > disk file via an array, search on search.cpan.org, or write your own > subclass to get the desired behaviour (I can't see much sense in using > Tie::StdScalar directly). > > Dani
I should have made clear my basic purpose in trying to use file-tied scalars. I wanted to put a very large file (.5GB) into a scalar in a way that has the system keeping most of the data on disk and putting in physical memory only what I need at any given moment. The problem statement is s'thing like $bigGulp = ` cat bigFile.txt` in order to do multi-line regexing. My first try with the application froze the rest of the system. I then configured linux with less virtual memory, and got an 'out of memory' error. i then turned -- naively it seems now -- to 'tie' etc. But after finding an implementation module for a file-tied scalar, I don't see now a solution via this route either, so I am resigned to using s'thing along the lines of File::Stream. (off topic for this list, but here it is anyhow: why can't you deal with this type of problem using linux virtual memory?) Hoping someone has some magic, Tom Arnall north spit, ca -- thanks, tom arnall north spit, ca -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>