Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do i sort a hash or array?

by moritz (Cardinal)
on Jan 21, 2008 at 13:11 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://663372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found