Tuesday, January 25, 2011

Exact twice occur

@crops = qw(wheat corn barley rice corn soybean hay
            alfalfa rice hay beets corn hay);
@dupes = grep { $count{$_} == 2 }                             #Exact two occurance
              grep { ++$count{$_} > 1 } @crops;               #more than two occurance
print "@dupes\n";

No comments: