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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.