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?
The config look like this:#!/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"; } }
<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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |