Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Sorting a hash value that is a list

by tangent (Deacon)
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 chanting in the Monastery: (7)
As of 2014-10-22 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls