my @IPMap = (
[ "host_1", "192.168.1.1" ],
[ "host_2", "192.168.1.2" ],
[ "host_3", "192.168.1.3" ],
);
or better, a hash:
my %IPMap = (
host_1 => "192.168.1.1",
host_2 => "192.168.1.2",
host_3 => "192.168.1.3",
);
YAML allows both structures to be generated directly from the configuration file. For example:
use strict;
use warnings;
use Data::Dump::Streamer;
use YAML ();
my $yamlStr = <<END_YAML;
---
host_1: "192.168.1.1"
host_2: "192.168.1.2"
host_3: "192.168.1.3"
---
-
- host_1
- "192.168.1.1"
-
- host_2
- "192.168.1.2"
-
- host_3
- "192.168.1.3"
END_YAML
my ($IPMapH, $IPMapAoA) = YAML::Load ($yamlStr);
Dump $IPMapH;
Dump $IPMapAoA;
Prints:
$HASH1 = {
host_1 => '192.168.1.1',
host_2 => '192.168.1.2',
host_3 => '192.168.1.3'
};
$ARRAY1 = [
[
'host_1',
'192.168.1.1'
],
[
'host_2',
'192.168.1.2'
],
[
'host_3',
'192.168.1.3'
]
];
True laziness is hard work
|