Tags:
create new tag
, view all tags
Sort uses cmp when sorting formfields. So numerical formfields get sorted lexically, which is wrong.

Propose to sort using the following sort function instead:

my $number = qr/^[-+]?[0-9]+(\.[0-9]*)?([Ee][-+]?[0-9]+)?$/;

sub _compare {
    if( $_[0] =~ /$number/ && $_[1] =~ /$number/ ) {
        # when sorting numbers to largets first; this is just because
        # this is what date comparisons need.
        return $_[1] <=> $_[0];
    } else {
        return $_[0] cmp $_[1];
    }
}
that allows numerical orderings on number data, though it's a bit unpredictable when mixed with lexical data..

-- CrawfordCurrie - 21 Apr 2005

 
Topic revision: r1 - 2005-04-21 - CrawfordCurrie
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by PerlIdeas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.