worley@compass.com (Dale Worley) (06/07/90)
I'm considering an application in which I have to read an arbitrary number of DBM files. I'd like to keep them all open at the same time as associative arrays. This leaves the little problem of associating array names with all of them, and of referencing an infinite number of array names. I can do this with 'eval', I suppose, but it sounds slow. Does anybody have any better idea? Dale Worley Compass, Inc. worley@compass.com -- "Bob" sold it. I bought it. That settles it. -- <_Jym_R_Dobbs_>
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (06/09/90)
In article <1990Jun7.151300.14429@uvaarpa.Virginia.EDU> worley@compass.com writes: : I'm considering an application in which I have to read an arbitrary : number of DBM files. I'd like to keep them all open at the same time : as associative arrays. This leaves the little problem of associating : array names with all of them, and of referencing an infinite number of : array names. I can do this with 'eval', I suppose, but it sounds : slow. Does anybody have any better idea? You're supposed to be able to use the *newname construct to do this, but I've been having trouble with it. The following OUGHT to work, but doesn't seem to. It does create the various files, and it does seem to put the data in the files, but then it seems to clobber the in core array when it exits the local somehow. Anyway, you might be able to fiddle this into something that works, or you might not. It would definitely be faster than eval if it can be made to work. #!./perl foreach $array ('foo', 'bar', 'baz') { local(*name) = $array; dbmopen(%name,$array,0666) || die "Can't open $array: $!\n"; %name = (1,2,3,4,5,6); } print "foo = ", keys(%foo), "\n"; print "bar = ", keys(%bar), "\n"; print "baz = ", keys(%baz), "\n"; dbmclose foo; dbmclose bar; dbmclose baz; Larry