Hi,

I am using the Config::General module to be able to use a config file. But if a user does not set all options I want to be able to go back to a default value. How can I set these?

#!/usr/bin/env perl use Getopt::Long; use Config::General; $PROGNAME = "myscript"; # Get Options from commandline my $nodename; usage() if ( @ARGV < 1 or ! GetOptions( "nodename=s"=>\$nodename )); my $conf = new Config::General( -ConfigFile => $PROGNAME . '.conf', -ExtendedAccess => 1 ); &read_config; sub read_config { if ($conf->is_hash($nodename)) { $config = $conf->obj($nodename); } else { print "Critical error: No configuration list found for $nodena +me\n"; } }
The config look like this:
<server1> host = server1.domain.tld ssl = true port = 443 username = admin password = qwerty vhost = example </server1> <server2> host = server2.domain.tld ssl = false port = 2080 username = admin password = qwerty vhost = example </server2>

I want to check if a value exists to the config key and if not set a default one. But I cannot seem to figure out how.

So any pointers to a solution would be greatly appreciated!


In reply to Config::General default config settings by Pascal2020

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.