I changed your hash to h, so no conflict with sort values:

my %h = ();

$h {"1"} = [ "some string","other string",3 ] ;
$h {"2"} = [ "some string","other string",2 ] ;
$h {"3"} = [ "some string","other string",1 ] ;

foreach my $MyKey (sort { $a->[1]<=>$b->[1] } map{[$_,$h{$_}[2]]} keys %h) {
   printf "%-s -> %-s\n", $MyKey->[0], $MyKey->[1];
}

Output:
3 -> 1
2 -> 2
1 -> 3


Wags ;)
-----Original Message-----
From: Michal Weinfurtner [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 25, 2002 01:21
To: [EMAIL PROTECTED]
Subject: Need help


Hi all ,

I have some data in hash of arrays and i need a print all of entries of
that hash sorted by 2-nd index of arrays. 

Example: 

$a {"1"} = [ "some string","other string","some number" ] ;
$a {"2"} = [ "some string","other string","some number" ] ;
$a {"3"} = [ "some string","other string","some number" ] ;
...
...
...
$a {"n"} = [ "some string","other string","some number" ] ;


I need print all hash entries sorted by "some number" (2-nd index of
arrays ). 

Any suggestions ? 

Thanks a lot 
Michal Weinfurtner 




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to