cmp uses alphabetical order, you want numerical order on the number alone. One simple solution would be to have a function to extract the number out of the key and do : @sortedKeys = sort { $planets{$a} <=> $planets{$b} or getNum($a) <=> getNum($b) } keys %cuantas_veces_sale;
This not the most effective solution, but it works well enough. To get the number inside the string you can use a regex like /(\d+)/, tr/// or substr depending on what you find the easier. The last two are perhaps more user-friendly, but require that your keys have a consistant format ("hs" and then the number for exemple).
In reply to Re: Sort hash keys
by Eily
in thread Sort hash keys
by cristianro87
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |