Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Finding maximum number of duplicates in an array

by vinoth.ree (Prior)
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


Comment on Re: Finding maximum number of duplicates in an array
Select or Download Code

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 browsing the Monastery: (6)
As of 2015-08-31 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (352 votes), past polls