Re: Missing something with Getopt::Std



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

.



Relevant Pages

  • Re: Division by Zero in Nature, and Decomposition of Time.
    ... >> Zero division has absolutely nothing to do with physical processes ... As others have commented when you are given a real reason (and Bobs response ... Spit paints stew - prove me wrong I dare you. ... in principle be performed and predicts something. ...
    (sci.math)
  • Re: Division by Zero in Nature, and Decomposition of Time.
    ... >> Zero division has absolutely nothing to do with physical processes ... As others have commented when you are given a real reason (and Bobs response ... Spit paints stew - prove me wrong I dare you. ... in principle be performed and predicts something. ...
    (sci.logic)
  • Re: Division by Zero in Nature, and Decomposition of Time.
    ... >> Zero division has absolutely nothing to do with physical processes ... As others have commented when you are given a real reason (and Bobs response ... Spit paints stew - prove me wrong I dare you. ... in principle be performed and predicts something. ...
    (sci.astro.amateur)
  • Re: Division by Zero in Nature, and Decomposition of Time.
    ... >> Zero division has absolutely nothing to do with physical processes ... As others have commented when you are given a real reason (and Bobs response ... Spit paints stew - prove me wrong I dare you. ... in principle be performed and predicts something. ...
    (sci.physics)
  • Re: Division by Zero in Nature, and Decomposition of Time.
    ... >> Zero division has absolutely nothing to do with physical processes ... As others have commented when you are given a real reason (and Bobs response ... Spit paints stew - prove me wrong I dare you. ... in principle be performed and predicts something. ...
    (sci.physics.relativity)