in reply to Re^3: Sort hash keys
in thread Sort hash keys

for my $nombre (keys %cuantas_veces_sale)

or

for my $nombre (sort {$a<=>$b} keys %cuantas_veces_sale)

i get hs12 hs22 hs11 hs10 hs7 hs20 hs16 hs4 hs18

for my $nombre (sort {$a cmp $b } keys %cuantas_veces_sale)

i get this hs1 hs10 hs11 hs12 hs13 hs14 hs15 hs16 hs17 hs18 hs19 hs2 hs20 hs21

i need this hs1 hs2 hs3 ... hs10 hs11 ...

Replies are listed 'Best First'.
Re^5: Sort hash keys
by LanX (Saint) on Mar 18, 2014 at 18:13 UTC
    true!

    DB<123> sub num { $_[0] =~/(\d+)$/; $1} DB<124> sort { num($a) <=> num($b) } qw/hs12 hs22 hs11 hs10 hs7 hs2 +0 hs16 hs4 hs18/ => ("hs4", "hs7", "hs10", "hs11", "hs12", "hs16", "hs18", "hs20", "hs +22")

    Cheers Rolf

    ( addicted to the Perl Programming Language)