A scalar value is interpreted as FALSE in the Boolean sense if it is undefined, the null string or the number 0 (or its string equivalent, "0"), and TRUE if it is anything else. The Boolean context is just a special kind of scalar context where no conversion to a string or a number is ever performed.
The number 0, the strings '0' and "" , the empty list (), and undef are all false in a boolean context. All other values are true. Negation of a true value by ! or not returns a special false value. When evaluated as a string it is treated as "" , but as a number, it is treated as 0. Most Perl operators that return true or false behave this way.
LanX already said that return just propagates the context of the sub call. Lists evaluated in scalar context return their last value, which is different from arrays, which return their size. Compare:
$ perl -wMstrict -le 'my $x = ("a","b","c"); print $x;' Useless use of a constant ("a") in void context at -e line 1. Useless use of a constant ("b") in void context at -e line 1. c $ perl -wMstrict -le 'my @y = ("a","b","c"); my $x = @y; print $x;' 3
One way to do what you want might be via the wantarray function:
return wantarray ? ($return,$values,$here) : $found_item_count;
In reply to Re: Subroutine evaluated as boolean
by Anonymous Monk
in thread Subroutine evaluated as boolean
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |