Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: conf file in Perl syntax

by GrandFather (Cardinal)
on Jun 11, 2009 at 21:11 UTC ( #770766=note: print w/ replies, xml ) Need Help??


in reply to Re^2: conf file in Perl syntax
in thread conf file in Perl syntax

Don't do that (parallel arrays). Either use an array of arrays (AoA):

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


Comment on Re^3: conf file in Perl syntax
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://770766]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (14)
As of 2014-08-22 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (163 votes), past polls