in reply to Re^2: hash sort
in thread hash sort

hello Anonymous Monk,

Regarding your question:

Ok , but its printing different 'key' everytime I run :(

Monk choroba already provided you the answer Re: hash sort:

#!usr/bin/perl use strict; use warnings; my %hash1 = ( '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1, ); my %hash2 = ( '1' => {'key' => 'a'}, '2' => {'key' => 'b'}, '3' => {'key' => 'a'}, '4' => {'key' => 'a'}, '5' => {'key' => 'b'}, ); foreach my $key1 ( sort { $hash2{$a}{'key'} cmp $hash2{$b}{'key'} || $a <=> $b } keys + %hash1) { print "key $key1 and $hash2{$key1}{key}\n"; } __END__ $ perl test.pl key 1 and a key 3 and a key 4 and a key 2 and b key 5 and b $ perl test.pl key 1 and a key 3 and a key 4 and a key 2 and b key 5 and b $ perl test.pl key 1 and a key 3 and a key 4 and a key 2 and b key 5 and b $ perl test.pl key 1 and a key 3 and a key 4 and a key 2 and b key 5 and b

I read your commend under the post of monk choroba Thank you. It works. Anyway to sort without rewriting main loop ? this is why I post the reply to your question.

Seeking for Perl wisdom...on the process of learning...not there...yet!