Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Finding maximum number of duplicates in an array

by vinoth.ree (Monsignor)
on Jan 30, 2014 at 09:40 UTC ( #1072652=note: print w/replies, xml ) Need Help??


in reply to Finding maximum number of duplicates in an array

Use hash and count the elements occurs in the array as follow.

use 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;
Output
$VAR1 = { 'e' => 1, 'a' => 2, 'd' => 2, 'c' => 1, 'h' => 2, 'b' => 1, 'g' => 1, 'f' => 2 };

All is well

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1072652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2016-09-25 17:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (470 votes). Check out past polls.