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 6939069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:34:29+00:00 2026-05-27T12:34:29+00:00

I’m building a script that utilizes a config file (YAML) to read in all

  • 0

I’m building a script that utilizes a config file (YAML) to read in all the necessary configuration information, then prints out all the necessary steps a Linux Admin needs to step through to build a server.

A required option is for the Linux Admin that’s running the script to be able to override any of the item/value pairs from the config file, at the command-line.

The way I’m currently handling this seems overly cumbersome and I know there’s got to be a more innovative and less clunky way to do this.


In the code I:

  1. Parse the YAML config file with YAML::Tiny

    location:
        continent: na
        country: us
        city: rh
    
  2. Create variables with the same names as the config file items, assigning the values from the config file.

    my $yaml = YAML::Tiny->new;
    $yaml = YAML::Tiny->read($config_yml);
    my $continent = $yaml->[0]->{location}->{continent};
    my $country = $yaml->[0]->{location}->{country};
    my $city = $yaml->[0]->{location}->{city};
    
  3. Use Getopt::Long and assign the variables, overriding anything passed at the command-line.

    GetOptions (
        "city=s" => \$city,
        "continent=s" => \$continent,
        "country=s" => \$country,
    );
    

So those are just 3 item/values pairs, my actual config has over 40 and will change…Which makes for a bit of work to have to keep updating. Any suggestions?

  • 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-05-27T12:34:29+00:00Added an answer on May 27, 2026 at 12:34 pm

    You can let the admin override the YAML settings with a single, flexible switch similar to what ssh(1) does with -o. This is especially appropriate if the config settings are numerous and likely to change.

    $ myscript -o location:city=rh --option location:country=us
    

    Now, inside the script, you might keep all your runtime config bundled together in a hash for convenience (rather than having $this_and_that_opt scalars proliferate over time). Option parsing would then look something like this:

    # First, set up %GlobalAppCfg from defaults and YAML
    # now handle "-o location:country=us"
    GetOptions('option|o=s' => sub {
                                  my (undef, $optstring) = @_;
    
                                  my ($userkey, $val) = split('=', $optstring, 2);
                                  my ($major, $minor) = split(':', $userkey,   2);
    
                                  $GlobalAppCfg->{$major}->{$minor} = $val;
                                },
                ...);
    

    or whatever. You can normalize config keys and values, handle arbitrarily deep key/subkey/subkey configs, etc. This can get slippery, so you might like to key-lock that global hash.

    • 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'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
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.