perl sort keys - hash numerically?
%hashnum=(21,2,44,11,55,5);
Method 1:[ascending order]
foreach $key (sort { $a <=> $b} keys %hashnum) { print $hashnum{$key} . "\n"; }
Method 2:[Descending order]
foreach $key (sort { $b <=> $a} keys %hashnum) { print $hashnum{$key} . "\n"; }
Labels: kaavannan perl blogspot, sort hash keys numerically, sort keys numerically
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home