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

  • Home
  • SEARCH
  • 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 7748327
In Process

The Archive Base Latest Questions

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

I have a perl script that’s reading an INI file like this: [placeholder_title] Hostname

  • 0

I have a perl script that’s reading an INI file like this:

[placeholder_title]
Hostname = 127.0.0.1
Port = 161

The library that I’m using for this is Config::Tiny.

Normally when reading the ini file, I would have something like this:

$Config = Config::Tiny->read( 'configfile.ini' );

my $Hostname_property = $Config->{placeholder_title}->{Hostname};

Now I have a case where the section title in the config file is decided by the user, so I don’t exactly know what it is.

Before I actually had multiple sections in the config file, so I would iterate through them like this:

 foreach my $Section (keys %{$Config}) {

            my $Hostname_property = $Config->{$Section}->{Hostname};
            my $Port_property = $Config->{$Section}->{Port};

But what if I were to have only 1 section in total?

Is there a particular keyword I can use to substitute for the section name?

I’ve tried the similar looping logic from the prior example something like this:

$Config = Config::Tiny->read( 'configfile.ini' );

my $Section = keys %{$Config};

my $Hostname_property = $Config->{$Section}->{Hostname};

print $Hostname_property, "\n";

But then I get an error that $Hostname_property is not initialized, so my $Section variable clearly isn’t doing what I hoped it to do.

If anybody can help me out or at least point me in the right direction, 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:45:23+00:00Added an answer on June 1, 2026 at 10:45 am

    The reason my $Section = keys %{$Config}; doesn’t work is that you’re calling keys in scalar context, so it’s returning the number of keys. Try calling it in list context instead:

    my ($Section) = keys %{$Config};
    

    This will set $Section to the first key. (“first” in whatever order keys is returning the keys in. If there’s only one key, that doesn’t matter.)

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

Sidebar

Related Questions

I have a Perl script that uses WWW::Mechanize to read from a file and
I have a Perl script, that's supposed to match this string: Sometimes, he says
I have a perl script that accepts a long option like --pager='less -R' and
I have a Perl script that works on Windows XP. It uses File::Copy's move
I have a Perl script that reads a command file and restarts itself if
I have a Perl script that I'd like to run on Windows, using either
I have this perl script that I need to distribute to my coworkers who
I have a really trivial perl script that I would like to distribute to
I have a perl script that is inserting records from a text file into
I have a Perl script that outputs text. I want to import this text

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.