On 15 Nov 2002, Matt Simonsen wrote: > I've tried using DB_File open a hash and write a hash of hashes to disk, > but this failed. I read in Perl Cookbook to "just use it as a regular > hash" but from what I can tell this is not possible when speaking of > complex structures like a hash of hashes. >
I'm not sure about that.... > I'm currently dumping this structure to disk in XML looping over all the > keys and values. I could read that back in to a hash each time my script > runs and update the hash, rewriting it to disk, but that would ding the > elegance of my script and so I'm trying to avoid it. This isn't exactly elegant. But it works: to write: use strict; use Data::Dumper; my $hr = {}; $hr->{foo} = "bar"; my $days = { mon => 1, tues => 2, wed => 3 }; $hr->{days} = $days; $hr->{aref} = ["a", "b", "c"]; my $file = "data_dump.txt"; open(F, ">$file") or die "Couldn't open file: $!"; print F Dumper $hr; Then to read it: use strict; use Data::Dumper; my $hr = do "data_dump.txt"; print Dumper $hr; If you need something more robust and efficient, look into the Storable module. It's quite nice. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]