View Full Version : Sorting by numerical VALUE?

08-07-2002, 03:38 AM
I am using a program called Newspro that automatically updates information on a website through a form in a web browser. There are a bunch of news items on my page beginning with letters and numbers, and I have them arranged in alphabetical order using the following subroutine:

sub NewsCatFilterAlpha {
my @NND = &NewsCatFilter(@_);
my @NNDsorted = map { $_->[0] }
sort{ $b->[1] cmp $a->[1] }
map { [ $_, $_->{'newstext'} ] } @NND;
return @NNDsorted;

The problem is that when a news item begins with a number, it places 10328 before 99, for example (ASCII sorting). I want it to sort by numerical value, the right way, not by the value of just the first digit. If anyone can help me with this it would really be a big help. Thanks.


08-07-2002, 11:31 PM
Try using <=> in place of cmp.

Take a look at this: