Re: Hash of arrays of hashes... There's got to be a cleaner way than this...
- From: Mark Clements <mark.clementsREMOVETHIS@xxxxxxxxxx>
- Date: Wed, 28 Feb 2007 22:52:30 +0100
tetchy wrote:
Hi,
I've been modifying a perl script that reads a configuration file,
validates the contents and generates a bunch of system configuration
files and an iptables firewall set. I discovered that the change from
ifconfig to iproute2 style files required a change in the way that
aliases were handled so the data no-longer fitted into my hash of arrays.
So I have created a hash keyed by interface containing an array of
hashes keyed by interface values ip, mtu, qdisc... etc. It took a while
but I now have a solution just it's a bit long winded and involves
creating a temporary hash.
<snip>
my %theInterfaceHash = (
'lo' => [ { ip => '127.0.0.1/8', mtu => '16436' } ],
'eth0' => [ { ip => '192.168.58.23/24', mtu => '1500' }, { ip => '192.168.48.23/24', mtu => '1500' }, { ip => '172.16.16.23/16', mtu => '1492' } ],
'eth1' => [ { ip => '192.168.44.23/24', mtu => '1500' } ]
);
I'd keep this data in an external file (YAML, XML or somesuch), and use a templating system to generate the config files.
eg
Template::Toolkit
HTML::Template (HTML is in the name, but it isn't restricted to HTML)
Mark
.
- References:
- Prev by Date: Re: change chr(9) ?
- Next by Date: Re: Parent process unable to read messages from child process
- Previous by thread: Hash of arrays of hashes... There's got to be a cleaner way than this...
- Next by thread: Rindex used to find end of a string
- Index(es):
Relevant Pages
|