in reply to hash sort

Sort by the $hash2{$_}{key} compared by cmp, if the values are the same, use the key for the secondary sort:
sort { $hash2{$a}{key} cmp $hash2{$b}{key} || $a <=> $b } keys %hash2

($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: hash sort
by Anonymous Monk on May 31, 2017 at 15:32 UTC
    Thank you. It works. Anyway to sort without rewriting main loop ?
    foreach my $key1 ( sort { $a <=> $b } keys %hash1 #main loop
    Thanks
      Anyway to sort without rewriting main loop ?

      No. You must interpolate the code given to you into the loop argument:

      foreach my $key1 ( sort { $hash2{$a}{key} cmp $hash2{$b}{key} || $a <=> $b } keys %hash1 ) {

      The loop body can remain as it is, I guess.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'