I am new to perl programming. And i am trying to do the configuration file using Config::Simple The configuration file i.e. new1.conf
[Section1] param1=value1 param2=value2 [Section2] param1=value1 param2=value2 [Section3] param1=value1 param2=value2
here is my code
use Config::Simple; $cfg = new Config::Simple(syntax => 'ini'); # # Get Section Names # $cfg = Config::Simple->import_from('new.conf', \%Config) or die Confi +g::Simple->error(); my @arr = ( keys %Config ); @arr1 = grep s/\..*//, @arr; my %uniq; @uniq{@arr} = (); @sections = keys %uniq; foreach my $secname (sort @sections) { print "section : $secname\n"; foreach (sort keys %Config) { print "$_ : $Config{$_}\n"; } }
For this i am getting the output like this
section : Section1 Section1.param1 : value1 Section1.param2 : value2 Section2.param1 : value1 Section2.param2 : value2 Section3.param1 : value1 Section3.param2 : value2 section : Section2 Section1.param1 : value1 Section1.param2 : value2 Section2.param1 : value1 Section2.param2 : value2 Section3.param1 : value1 Section3.param2 : value2 section : Section3 Section1.param1 : value1 Section1.param2 : value2 Section2.param1 : value1 Section2.param2 : value2 Section3.param1 : value1 Section3.param2 : value2
I am trying to compare the section names with paramaters in that respective section. for that i am trying to write this code
foreach my $secname (sort @sections) { print "section : $secname\n"; foreach (sort keys %Config) { $var = grep { !/\b[A-Za-z0-9.].*[.]/ } @arr; if($secname == $var) { print "$secname\n"; } else { print "false\n"; } #compare 'secname' vs 'dialer onboard'.xxx #print "$_ : $Config{$_}\n"; } }
This is not working for me. I stuck up here only I cant be able to compare and display the section name with the respective params and values.
And finally i want output like this below.
section : Section1 Section1.param1 : value1 Section1.param2 : value2 section : Section2 Section2.param1 : value1 Section2.param2 : value2 section : Section3 Section3.param1 : value1 Section3.param2 : value2
or at least i want to display the params. I think i am doing something wrong in comparing params and section. I am not able to identify that. Please somebody suggest me where i am going wrong Thanks in advance.
In reply to perl: Config::Simple config file reading by abhi1390
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |