in reply to Re: Check if value exists into an array in a hash
in thread Check if value exists into an array in a hash

The issue is that push @list, $num doesn't set element $list[$num], so the tests don't correlate. If instead the OP used $list[$num] = 1; or equivalent, then [she|he] would get a false positive with exists if [she|he] set $list[5] and then checked $list[3] - defined would give correct results, though.

Replies are listed 'Best First'.
Re^3: Check if value exists into an array in a hash
by pileofrogs (Priest) on Feb 10, 2009 at 21:53 UTC

    Oy, yes. I see what you mean. The array will grow to accomodate it's highest index, and therefore all lower indexes will come into existence.

    I think the OP should use a hash. Clearly, it's a hash-ish behavior he/she wants. The fact that the keys are numbers is making it look like a list problem, but really, it's a hash problem.