|Pathologically Eclectic Rubbish Lister|
sorting hashesby olecs (Scribe)
|on Apr 20, 2005 at 07:21 UTC||Need Help??|
olecs has asked for the wisdom of the Perl Monks concerning the following question:
Hello all, I'm having a bit of trouble sorting hashes numerically.
I create the hash entrys like this:
For each $recNo there can be a lot of $i - both $recNo and $i are numeric.
Everything is stored properly and I can easily access it, but I can't manage to sort $i numerically.
Here is how I (try to) do it:
$k1 is in the correct order, $k2 is not (rather random it seems). If I am doing an ascii sort for $k2, like this:
it sorts correctly by ascii value, which doesnt help me much, but atleast indicates that it should be possible to sort it :)
Also, $k1 seem to be sorted correctly (numerically), why is this? I thought it sorted on ascii values unless asked to do otherwise with the <=> operator.
If someone could shed some light on this (particularly the sorting of $i) I would be very gratefull.