Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: sorting hashes

by johnnywang (Priest)
on Apr 20, 2005 at 07:28 UTC ( [id://449511]=note: print w/replies, xml ) Need Help??


in reply to sorting hashes

not sure what you're doing in the sorting of $k2, the following seem to be what you want (not tested):
my $rHash = \%hash; for my $k1 = (sort keys %$rHash) #outer key, this works { for my $k2 (sort {$a <=> $b} keys %{$rHash->{$k1}}) ) { #display miscellaneous print $k1 $k2; } }

Replies are listed 'Best First'.
Re^2: sorting hashes
by blazar (Canon) on Apr 20, 2005 at 07:39 UTC
    The same cmt I already gave to the OP applies: this can't be what he wants for it wouldn't even compile. Correcting the typo indeed this could be what he wants.

    Oh, and BTW:

    print $k1 $k2;
    Aren't we missing something here too?!?
      Hello again,
      the = sign was a typo that is not present in my original code - sorry about that, same with the print statement - was just to indicate that there was some output.

      The solution was indeed to use sort with just $a and $b - yep, Perl is not my first language.

      Thank you all for the exceptionally quick replies.

      rgds,
      Ole C.
        Hello again,
        the = sign was a typo that is not present in my original code - sorry about that, same with the print statement - was just to indicate that there was some output.
        There's a lesson in this, and an oft advocated one: do not retype code, paste it. (In this case not much harm was being done, but it's a good general rule to stick to, if possible.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://449511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found