Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Need help fixing AppConfig error ("global_password: no such variable")

by crackotter (Beadle)
on Jun 11, 2003 at 17:09 UTC ( [id://265100]=perlquestion: print w/replies, xml ) Need Help??

crackotter has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am writing a script using the AppConfig module to load from values from a flat config file. I want comment out a value in the Config file and not have AppConfig throw an error. here is a example CODE:
#!/usr/bin/perl use strict; use AppConfig qw(:expand :argcount); #Create $config object my $config = AppConfig->new({ GLOBAL => { ARGCOUNT => ARGCOUNT_ONE, DEFAULT => "", }, CREATE => 1, }); #open config file unless ($config->file("config.conf")) { die "Could not open or find configuration file.\n"; } my $user_name = $config->get("global_username"); my $password = $config->get("global_password");
With the following config file, config.conf:
[GLOBAL] #Set you username username = default #Do not uncomment unless you need to #password = default
If if do it this way currently, AppConfig throws an error:
" global_password: no such variable"
What can I do to fix this?

edited: Thu Jun 12 12:09:00 2003 by jeffa - title change (was: AppConfig)

Replies are listed 'Best First'.
Re: Need help fixing AppConfig error ("global_password: no such variable")
by kabel (Chaplain) on Jun 11, 2003 at 19:14 UTC
    there are two possibilities:

  • ovverriding the error handler
  • my $config = AppConfig->new({ GLOBAL => { ARGCOUNT => ARGCOUNT_ONE, DEFAULT => "", }, CREATE => 1, ERROR => sub {} });

  • defining the parameter manually
  • # config parameters that could eventually be empty $config->define (qw ( global_password ) );
    the second alternative is definitely to prefer.
Re: Need help fixing AppConfig error ("global_password: no such variable")
by jdavidboyd (Friar) on Jun 11, 2003 at 19:15 UTC
    The quick dirty ugly way would be to define your own error handler, and ignore it.

    I did that here, adding in
    sub my_error() { }

    And defining an error tag above your GLOBAL line, like
    ERROR => \&my_error,

    When I run, I get no error about global_password not existing.
    Of course, YMMV. Personally, I wouldn't ignore any errors if I could help it.

    Or, you could use the CREATE tag to make variables automatically that don't exist and set them to their default values.
Re: Need help fixing AppConfig error ("global_password: no such variable")
by crackotter (Beadle) on Jun 11, 2003 at 21:10 UTC
    I did the following:
    $config->define ("global_password");
    at first I put it after the $config->file section.. (my mistake) but after I moved it before that section, everything works perfect.
    Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://265100]
Approved by Tomte
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found