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

Re: Sorting a hash value that is a list

by tangent (Curate)
on Feb 26, 2012 at 23:45 UTC ( #956341=note: print w/ replies, xml ) Need Help??


in reply to Sorting a hash value that is a list

[interesting username]
You could create a hash to keep track of your users like so:

my %seen = (); while(<FILE>) { chomp; ($host, $grp, $gid, $userid) = split(/:/, $_); $group = "$grp:$gid"; # check to see if we've seen this group/user already next if $seen{$group}{$userid}++; push @{$table{$group}}, $userid; } Prints: group1:9001:user1,user2,user3,user4,user5 group1:9006: group2:9002:user1,user2,user3 group3:9003:user1,user2,user4 group4:9004:user1,user2,user5 group5:9005:user1,user2 group6:9006: 7
Note that $seen{$group}{$userid}++ only increments after the check


Comment on Re: Sorting a hash value that is a list
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2015-07-07 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls