Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Sorting an array or hashes

by moritz (Cardinal)
on Jan 23, 2012 at 08:51 UTC ( [id://949337]=note: print w/replies, xml ) Need Help??


in reply to Sorting an array or hashes

@sortedCollectionData = sort { $collectionData[ $b ]{CollectionId} <=> $collectionData[ $a ]{Coll +ectionId} || $collectionData[ $b ]{Modified} cmp $collectionData[ $a ]{Modified +} } 0 .. $#collectionData;

What you are storing here are numbers (specifically from 0 to $#collectionData), so @sortedCollectionData now contains these numbers in some order or another. And then you write $sortedCollectionData[$i]{'Status'}, and try to access one of these numbers as if it was a hash reference.

You might want to sort your hash refs directly instead:

@sortedCollectionData = sort { $b->{CollectionId} <=> $a->{CollectionId} || $b->{Modified} cmp $a->{Modified} } @collectionData;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-23 21:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found