Re: Missing something with Getopt::Std
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 2 Dec 2005 12:51:03 -0800
sunckell wrote:
> I am trying to pass an arguement to a script I have but for some
> reason Getopt::Std is not grabbing the value. I am also using
> Config::IniFiles.
>
> Is there something in the perldoc that I am missing about passing a
> '0' (zero) from a command line perameter?
No, there's something you're not understanding about either the ?:
operator or boolean values in Perl.
> getopts('c:D:F:L:s:d:hV', \%opts);
>
> $log_debug = ($opts{'L'} ? $opts{'L'} : $cfg->val('LOGGING',
> 'debug'));
>
> if $cfg->val('LOGGING', 'debug') is set as 0 in the ini file, I can
> pass a '1' as -L and the value is set as '1'. But if the value in the
> ini file is set to 1, I cannot override it if I use -L 0 at the command
> line.
$x ? $y : $z
is exactly equivalent to
if ($x){
$y;
} else {
$z;
}
In your example, $x is zero. Zero is a false value. Therefore, the
"else" condition is evaluated, that being the 1 that is stored in $cfg.
I think you actually want to test if $x is *defined*, not whether or
not it's true:
$log_debug = (defined $opts{'L'} ? $opts{'L'} :
$cfg->val('LOGGING','debug'));
check out:
perldoc -f defined
perldoc perlsyn
Paul Lalli
.
- Follow-Ups:
- Re: Missing something with Getopt::Std
- From: sunckell
- Re: Missing something with Getopt::Std
- References:
- Missing something with Getopt::Std
- From: sunckell
- Missing something with Getopt::Std
- Prev by Date: Re: Convert date to timestamp
- Next by Date: Referring to the calling script from a module
- Previous by thread: Re: Missing something with Getopt::Std
- Next by thread: Re: Missing something with Getopt::Std
- Index(es):
Relevant Pages
|