in reply to sub fails second time called

From defined:
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; }

Replies are listed 'Best First'.
Re^2: sub fails second time called
by jdagius (Initiate) on Apr 24, 2008 at 19:54 UTC
    Brother Monks,

    I now understand why the sub failed and have used your ideas to create a correctly working function.

    I also submitted a bug report on List::Member at cpan.org.

    Thanks!
    Johanus