Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Finding maximum number of duplicates in an array

by vinoth.ree (Parson)
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 exploiting the Monastery: (8)
As of 2014-12-25 22:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls