skx has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I've got a simple problem with a configuration file parser/settings object.
I've written a simple module which allows access to configuration values, and I find that I'm not able to differentiate between a value that is unset, and a value that is zero easily.
Consider the following:
my $value = getConfigValue( "use_foo" ) || 1;
What I want to do is to say read the value, and if it's not defined use '1' as a default. What actually happens is that if the value is set to '0' it gets ignored.
I see the following as a solution:
my $value = getConfigValue( "use_foo" ); if ( !defined( $value ) ) { $value = 1; }
but that seems a little messy.
Short of re-writing the code to be 'getConfigValue( "keyname", "default" )' which would be a pain is there a simple solution?
Steve
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: undef vs 0
by robartes (Priest) on Feb 06, 2003 at 09:49 UTC | |
Re: undef vs 0
by PodMaster (Abbot) on Feb 06, 2003 at 10:00 UTC | |
by skx (Parson) on Feb 06, 2003 at 11:30 UTC | |
Re: undef vs 0
by bart (Canon) on Feb 06, 2003 at 11:51 UTC | |
Re: undef vs 0
by ehdonhon (Curate) on Feb 06, 2003 at 11:30 UTC | |
Re: undef vs 0
by pfaut (Priest) on Feb 06, 2003 at 15:54 UTC | |
by skx (Parson) on Feb 06, 2003 at 19:06 UTC | |
Re: undef vs 0
by TheDamian (Vicar) on Feb 07, 2003 at 17:17 UTC | |
Re: undef vs 0
by PureSignal (Initiate) on Feb 06, 2003 at 18:30 UTC | |
Re: undef vs 0
by thinc (Novice) on Feb 07, 2003 at 06:48 UTC |