Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: sort a hash with split values

by TedPride (Priest)
on Jun 22, 2006 at 04:00 UTC ( [id://556822]=note: print w/replies, xml ) Need Help??


in reply to sort a hash with split values

Well, you could just dump the usernames into state buckets and then retrieve them by state:
use strict; use warnings; my (%hash, %states); while (<DATA>) { chomp; @_ = split /: /, $_, 2; $hash{$_[0]} = $_[1]; } for (keys %hash) { push @{$states{(split /:/, $hash{$_})[1]}}, $_; } for (sort keys %states) { print $hash{$_}, "\n" for @{$states{$_}}; } __DATA__ alpha: 12:NY:me@yoiu.com beta: 13:MO:fg@yoiu.com gamma: 14:DE:fghh@yoiu.com delta: 15:MO:adf@yoiu.com epsilon: 16:DE:mjhg@yoiu.com iota: 17:NY:juyu@yoiu.com eta: 18:NY:mjhk@yoiu.com
The transform method is so much neater, though.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found