Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Unique value count in hash not working properly

by Khen1950fx (Canon)
on Oct 01, 2011 at 09:49 UTC ( [id://929023]=note: print w/replies, xml ) Need Help??


in reply to Unique value count in hash not working properly

I haven't done a counter in ages:). Would this help?
#!/usr/bin/perl -slw use strict; my %count; my(@dates) = ( 9.1.11, 9.2.11, 9.3.11, 9.4.11, 9.5.11 ); foreach my $batch_dates (@dates) { ++$count{$_} foreach (@dates); sleep 1; print $count{$batch_dates}; }
Update: I added List::MoreUtils for a unique counter:
#!/usr/bin/perl -slw use strict; use List::MoreUtils qw(uniq); my %count; my (@nums) = uniq 9.2.11, 9.2.11, 9.2.11, 9.4.11, 9.5.11; foreach my $num (@nums) { ++$count{$_} foreach (@nums); sleep 1; print $count{$num}; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-18 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found