in reply to Sort hash keys

I suppose you want

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

Though you haven't been clear what %planet holds.

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: Sort hash keys
by cristianro87 (Initiate) on Mar 18, 2014 at 17:29 UTC

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

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