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
---
steve.org.uk
In reply to undef vs 0
by skx
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.