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.
In reply to Re^3: hash sort
by shmem
in thread hash sort
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |