Re: Hash of arrays of hashes... There's got to be a cleaner way than this...



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
.



Relevant Pages

  • Netscreen Pen-Test
    ... Netscreen firewalls, for example, the Netscreen 5GT, keep a hash of the admin login and password in the configuration file. ...
    (Pen-Test)
  • Hash of arrays of hashes... Theres got to be a cleaner way than this...
    ... I've been modifying a perl script that reads a configuration file, ... aliases were handled so the data no-longer fitted into my hash of arrays. ... hashes keyed by interface values ip, mtu, qdisc... ...
    (comp.lang.perl.misc)
  • Re: problem with large hash vanishing
    ... > configuration file into a hash of hashes. ... Depending on the format of the config file, you may be able to use a CPAN ...
    (comp.lang.perl.misc)
  • Re: Converting to JSP
    ... As part of converting a website to JSP, ... internal link would have to be renamed from *.html to *.jsp. ... Is it possible using just some sort of configuration file to use ...
    (comp.lang.java.softwaretools)
  • Re: configuration files with automake & autoconf
    ... Hash: SHA1 ... > I want to place my configuration file in /etc is there any way to do so ... Printing on GNU/Linux? ...
    (comp.os.linux.misc)