Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: keep only unique elements in an array displaying number of duplcates.

by GotToBTru (Prior)
on Jul 28, 2014 at 04:25 UTC ( [id://1095283]=note: print w/replies, xml ) Need Help??


in reply to keep only unique elements in an array displaying number of duplcates.

Your code could be more efficient, but examining %seen at the end shows you have the data you want. You just need to display it. keys %hashvariable produces a list of the keys of a hash.

foreach my $name (sort keys %seen) { printf "%-6s: %-2d\n", $name, $seen{$name}; }

Output:

dave : 2 james : 2 jon : 5 ken : 3 mike : 3

Or, slightly more 'perlish',

printf "%-6s: %-2d\n",$_, $seen{$_} for (sort keys %seen);
1 Peter 4:10

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-20 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found