Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 chilling in the Monastery: (2)
As of 2025-12-06 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (85 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.