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

I updated the code, the planets things was just a test and i copy the wrong code

Replies are listed 'Best First'.
Re^3: Sort hash keys
by LanX (Saint) on Mar 18, 2014 at 17:41 UTC
    > I updated the code, the planets things was just a test and i copy the wrong code

    please see How do I post a question effectively? and How (Not) To Ask A Question to avoid wasting our time.

    in this special case numeric sort works

    DB<106> sort {$a <=> $b } @keys => ( "hs5", "hs6", "hs7", "hs8", "hs9", "hs10", "hs11", "hs12", "hs13", "hs14", "hs15", )

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      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 ...

        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)