F
fatgirl.brown
Hi, I have a two-dim array as hash value and I want to sort it:
# <code>
#!/usr/bin/perl -w
push @{$hash{"test"}}, [10, "hi1"];
push @{$hash{"test"}}, [3, "hi2"];
push @{$hash{"test"}}, [5, "hi3"];
push @{$hash{"test"}}, [1111, "hi4"];
@{$hash{"test"}} = sort {$a <=> $b} @{$hash{"test"}};
print join " ", @{$hash{"test"}[0]};
print "\n";
# </code>
But it prints "5 hi3". So it put the 5 first, although the 3 should be
first after it's sorted. How can I sort so that it's 3, 5, 10, 1111?
Thanks!!
Junupa
# <code>
#!/usr/bin/perl -w
push @{$hash{"test"}}, [10, "hi1"];
push @{$hash{"test"}}, [3, "hi2"];
push @{$hash{"test"}}, [5, "hi3"];
push @{$hash{"test"}}, [1111, "hi4"];
@{$hash{"test"}} = sort {$a <=> $b} @{$hash{"test"}};
print join " ", @{$hash{"test"}[0]};
print "\n";
# </code>
But it prints "5 hi3". So it put the 5 first, although the 3 should be
first after it's sorted. How can I sort so that it's 3, 5, 10, 1111?
Thanks!!
Junupa