Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How do i sort a hash or array?

by moritz (Cardinal)
on Jan 21, 2008 at 13:11 UTC ( #663372=note: print w/replies, xml ) Need Help??


in reply to How do i sort a hash or array?

You have chosen a really bad representation for sorting.

You could transform your data to an array of hashes instead:

my @persons = { firstname => 'name1', lastname => 'lname1', city => 'city1', }, { firstname => 'name2', lastname => 'lname2', city => 'city2', }, ... );

And then sort with sort { $a->{firstname} cmp $b->{firstname} } @persons.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2018-10-15 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (82 votes). Check out past polls.

    Notices?