Hello Mellotto,
Thursday, August 23, 2001, Mellotto <[EMAIL PROTECTED]> wrote:
M> I've tried to sort hash values. The following file shows my problem:
M> ----------------------------------------------------
M> #!/opt/perl5/bin/perl
M> %map = (
M> 1 => 1,
M> 2 => 10,
M> 3 => 200,
M> 4 => 2,
M> 5 => 5,
M> 6 => 150,
M> 7 => 45,
M> 9 => 12,
M> 8 => 30,
M> 10 => 13,
M> );
M> for (sort {$map{$a} <=> $map{$b} || sort $b } keys %map) {
M> printf("%d;%d\n", $_, $map{$_});
M> }
M> ----------------------------------------------------
M> The output for this script:
M> 1;1
M> 4;2
M> 5;5
M> 2;10
M> 9;12
M> 10;13
M> 8;30
M> 7;45
M> 6;150
M> 3;200
M> I need to sort numerically by first column. I've written it
M> in many ways, but it still sorting by second column.
M> Could you help me solve this problem?
for (sort {$a <=> $b} keys %map) {
printf("%d;%d\n", $_, $map{$_});
}
Best wishes,
Maxim mailto:[EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]