Why does my Perl program print a help message when the arguments have 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 as follows:

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

this always leads to a call to use (), so it is obvious that 0 is not considered an integer value. What can I accept integer values ​​AND 0?

+6
integer parameters perl zero getopt-long
source share
1 answer

When viewed as a boolean, 0 is considered a false Perl value

You need something like

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

EDIT

Also see msw comment on original question

+11
source share

All Articles