in reply to Re: Ini files
in thread Ini files

Yes I forgot my $i. Now the syntax of the code is correct. What I want to do is to be able to assosiate slots with indices for every host using ini file format. Can you help me please, cause I am new to perl...

Replies are listed 'Best First'.
Re^3: Ini files
by Anonymous Monk on Sep 04, 2009 at 09:55 UTC
    Don't struggle with ini, use YAML
    #!/usr/bin/perl -- use strict; use warnings; use YAML; use Data::Dumper; sub printdump { print Dump($_[0]),"\n\n"; print Data::Dumper->new([$_[0]])->Indent(1)->Dump,"\n"; print "---------- $_[0] ----------\n"; } { my %ini; $ini{performance}{pop1}{ip} = q{192.168.1.1}; $ini{performance}{pop1}{slots} = [ {2 => 123}, {2 => 345}, {4 => 125}, ]; $ini{performance}{pop2} = {}; $ini{performance}{pop2}{ip} = q{192.168.1.2}; $ini{performance}{pop2}{slots} = [ {6 => 503}, {10 => 444}, ]; printdump(\%ini); } { my %ini; $ini{performance}{pop1}=[ q{192.168.1.1}, {2 => 123}, {2 => 345}, {4 => 125}, ]; $ini{performance}{pop2} = [ q{192.168.1.2}, {6 => 503}, {10 => 444}, ]; printdump(\%ini); } { my %ini; $ini{performance}{pop1}=[ q{192.168.1.1}, [2 => 123], [2 => 345], [4 => 125], ]; $ini{performance}{pop2} = [ q{192.168.1.2}, [6 => 503], [10 => 444], ]; printdump(\%ini); } { my %ini; $ini{performance}{pop1} = [qw[ 192.168.1.1 2 123 2 345 4 125 ]]; $ini{performance}{pop2} = [qw[ 192.168.1.2 6 503 10 444 ]]; printdump(\%ini); } { my %ini; $ini{pop1} = [qw[ 192.168.1.1 2 123 2 345 4 125 ]]; $ini{pop2} = [qw[ 192.168.1.2 6 503 10 444 ]]; printdump(\%ini); } __END__
    or even JSON