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?
P.S. Please forgive me for the dual post. I first posted this in the Q&A and then realized I should have posted it here.
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";
}
}
};
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.