Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:33:06+00:00 2026-06-01T10:33:06+00:00

I’m making a Perl script that needs to read and obtain the values of

  • 0

I’m making a Perl script that needs to read and obtain the values of an INI file.

INI File Format:

[name]
Property=value

Example:

[switch_6500]
cpu=1.5.1.12.4
free_memory=1.45.32.16

[oracle_db_11g]
param1=value1
param2=value2
param3=value3
param4=value4
...

As you can see, there can be any amount of sections, that contain any number of parameters. The names of the section names/parameters will always be different.

What I need to do is have my Perl script iterate through every section, and obtain all parameter names/values of that section. What I’m used to doing with INI files is simply specifying the section name along with the name of the parameter like this:

  #!/usr/bin/perl -w

  use strict;
  use warnings;
  use Config::Tiny;

  # Read the configuration file
  my $Config = Config::Tiny->new();
  $Config = Config::Tiny->read( 'configfile.ini' );
  my $Metric1_var = $Config->{switch_6500}->{cpu};
  my $Metric2_var = $Config->{switch_6500}->{free_memory};

However, now that I have an indefinite amount of section names/parameters, as well as not knowing their names, I can’t seem to figure out a way to extract all the values. I was looking around at the Config::IniFiles module, and it has some interesting stuff, but I can’t seem to find a way to obtain a parameter value without knowing the section/parameter name.

If anyone can help me with iterating through this INI file, it would be greatly appreciated.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:33:07+00:00Added an answer on June 1, 2026 at 10:33 am

    You can do what you want with Config::Tiny. Simply use the keys function to iterate over all of the keys of the hash, as follows:

    use strict;
    use Config::Tiny;
    
    my $config = Config::Tiny->read('configfile.ini');
    
    foreach my $section (keys %{$config}) {
        print "[$section]\n";
        foreach my $parameter (keys %{$config->{$section}}) {
            print "\t$parameter = $config->{$section}->{$parameter}\n";
        }
    }
    

    Note: Because hashes are “hashed”, and not ordered like arrays are, the order of keys returned may seem nonsensical. Since order doesn’t matter in an INI file (only the placement of which parameters are in which section matters), this shouldn’t be a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.