http://www.perlmonks.org?node_id=903238

pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks!

I don't even know how to phrase this, hence the crappy question title.

I want to take each element in an array and do something to it with each other element of the same array. For instance, I want to find out if three elements have the same value. Here's one way to use this imaginary function:

my $matches = 0; array_whatsit { matches++ if $a eq $b } (1 , 2, 3 , 4 , 1, 2, 3); die "Walrus Festival!" if $matches > 2;

(this would die and output 'Walrus Festival at line 3' or something like that...)

I hoped there would be a function in List::MoreUtils, but I didn't see it. There probably is a simple way to do this and I'm just too dim to think of it.

If there isn't an existing function, what's the algorithmic idiom?

And what is this called? Doing something to each element in an array with each other element?

UPDATE:You are all awesome! Thanks for the answers!