my $input = 0;
my $flag = $input || 1;
The value of $flag is '1'. To be sure, it is not a surprising matter because '0' is evaluated as 'false' in Perl. This is a very famous pitfall of idim in Perl.
There's More Than One Way To Do It. I did it like this for now.
my $input = 0;
my $flag = defined $input ? $input : 1;

0 件のコメント:
コメントを投稿