For When You Can't Have The Real Thing
[ start | index | login ]
start > perl > simple numeric sort

simple numeric sort

Created by dave. Last edited by dave, 19 years and 152 days ago. Viewed 3,784 times. #1
[edit] [rdf]
labels
attachments

Simple Numeric Sort

Wrong:

foreach $item (sort(keys(%Dictionary)))

Right:

foreach $item (sort { $a <=> $b } keys (%Dictionary))

The first example does a string sort, so in this case you can end up with sequences which look like

  • 1 2 3 44 5
The second example returns the correct order.
no comments | post comment
This is a collection of techical information, much of it learned the hard way. Consider it a lab book or a /info directory. I doubt much of it will be of use to anyone else.

Useful:


snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt