Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Sorting by numerical VALUE?

    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.

    Josh

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try using <=> in place of cmp.

    Take a look at this:
    http://www.perldoc.com/perl5.8.0/pod/func/sort.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •