in reply to Finding maximum number of duplicates in an array
Use hash and count the elements occurs in the array as follow.
Outputuse strict; use warnings; use Data::Dumper; my %count; grep { ++$count{$_} } qw(a b a c d d e f g f h h); print Dumper \%count;
$VAR1 = { 'e' => 1, 'a' => 2, 'd' => 2, 'c' => 1, 'h' => 2, 'b' => 1, 'g' => 1, 'f' => 2 };
|
|---|