Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my Perl program print the help message when an arguments has 0 as a value?

If i do this:

GetOptions(
    'u=s'    => \$in_username,
    'r=i'   => \$in_readonly,
    'b=i' => \$in_backup
    );

exit usage() unless $in_username && $in_readonly && $in_backup;

and call the program like this:

./app.pl -u david -r 12 -b 0

it always results in calling usage(), so obviously the 0 is not seen as an integer value. What can i do accept integer values AND 0?

like image 985
David Avatar asked Mar 10 '10 15:03

David


1 Answers

When treated as a boolean, 0 is considered to be a false value by Perl

You need something like

exit usage() unless defined($in_username) && defined($in_readonly) && defined(in_backup);

EDIT

Please also see msw's excellent comment to the original question

like image 94
Dancrumb Avatar answered Sep 19 '22 18:09

Dancrumb