Use of "defined" on aggregates (hashes and arrays) is deprecated. It used to report whether memory for that aggregate has ever been allocated. This behavior may disappear in future versions of Perl. You should instead use a simple test for size:As an optimization, perl is reusing the same @found array across multiple function calls, and since the second call to member allocates memory for the array, defined() returns true, even on the third call.
Since you don't actually need an array of results, you might want to do something like this instead:
my $found; ($found) = grep ...; if (defined $found) { return $found + 1; } else { return 0; }
In reply to Re: sub fails second time called
by ysth
in thread sub fails second time called
by jdagius
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |