gnu@perl has asked for the wisdom of the Perl Monks concerning the following question:

I have been using a text file for a config file. I now wish to put this into a dbm file on disk and tie a hash to it. This will take the loading of the text file into a hash of hashes out of my program. The problem I seem to have (I think) is that you cannot tie a file on disk to a hash of hashes. It seems that the multi-dimensional nature of the HoH prevents. this. Any ideas?
use strict; use Fcntl; use NDBM_File; my $configFile = "$ENV{HOME}/\.logmConfig"; my %prefs; tie %prefs, "NDBM_File", "$configFile", O_RDWR|O_CREAT, 0644 or die "C +annot tie to $configFile:\n$!\n"; %prefs = ( 'hopper.uslec.net' => { '/u20/gvc/log/log.log' => 50, '/u20/gvc/log/log2.log' => 12, }, ); print_hash(); untie %prefs; sub print_hash{ my ($server,$log,$lines); foreach $server (keys %prefs) { print "$server\n"; foreach $log ( keys %{ $prefs{$server} } ) { print " $log\n"; print " $prefs{$server}{$log}\n"; } } };

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: using tie on a Hash of Hashes
by blakem (Monsignor) on Aug 16, 2002 at 17:52 UTC
    check out MLDBM

    Originally posted as a Categorized Answer.