If some values are repeated in array2, the hash will have only the unique values as keys (there will be fewer hash keys than there are array elements). But why would that be a problem? In your comment about what you've "been thinking of" (making a hash of arrays), you mention some sort of "information" associated with each number, but what is this "information" and where does it come from? The array is just a list of numbers (some of which might appear more than once).
If it's important to know how many times a given value occurs in array2, just load and use the hash like this:
And of course, for any value that is repeated in array1 and happens to match a value found in array2, "do_something()" will happen each time that value comes up.my %a2hash; $a2hash{$_}++ for ( @array2 ); for ( @array1 ) { if ( exists( $a2hash{$_} )) { # use the value that matched, and number of matches in @array2 +: do_something( $_, $a2hash{$_} ); } }
If the question is simply "which of the values in array1 are also found in array2?", then a simple hash with array2 values as keys is all you need, regardless of whether the values are repeated.
Did you maybe leave out some other aspect of the question?
In reply to Re: finding exists on non unique information
by graff
in thread finding exists on non unique information
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |