Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: perl: Config::Simple config file reading

by 1nickt (Canon)
on Jul 24, 2015 at 23:23 UTC ( [id://1136244]=note: print w/replies, xml ) Need Help??


in reply to perl: Config::Simple config file reading

UPDATE: You also cross-posted this question on Stackoverflow. It's good form to mention that and provide a link.

There are problems with your code. You should always use strict; at the top of all your code and let Perl find some of your errors for free.

But besides that you are using a module that doesn't return the data in the way you want. You should use Config::Tiny which is only for ini-style files, and returns a reference to a hash structure as you want:

#! perl -w use strict; use feature qw/ say /; use Config::Tiny; my $cfg = Config::Tiny->new; $cfg = Config::Tiny->read('new.conf') or die $!; foreach my $section (sort keys %{ $cfg }) { say "section: $section"; foreach my $param (sort keys %{ $cfg->{ $section } }) { say "$section.$param : $cfg->{ $section }->{ $param }"; } } __END__
The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-23 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found