Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to Sort a Hash According to the Keys in the Hash

by choroba (Cardinal)
on Dec 02, 2015 at 18:44 UTC ( [id://1149199]=note: print w/replies, xml ) Need Help??


in reply to How to Sort a Hash According to the Keys in the Hash

You can't retrieve the order of the keys from a normal hash. It's too late - the hash is already unsorted.

However, you can use Tie::IxHash:

use Tie::IxHash; tie my %h, 'Tie::IxHash'; %h = ( Sports => ["Soccer","UltimateFrisbee","Basketball"], Books => ["Cannery Row", "Animal Farm", "East of Eden"], Places => ["BigSur","Zion", "CrateLake"] ); print "$_\n" for keys %h;
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: How to Sort a Hash According to the Keys in the Hash
by ishootperls (Novice) on Dec 02, 2015 at 19:15 UTC

    Outstanding !! Wasn't aware of such module. Thanks choroba !!

    "An incendiary Perl will solve that problem" :-) - myself

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-25 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found