On Thu, Jan 18, 2001 at 08:13:40PM -0500, Scott R. Godin wrote:
> on 01/11/2001 03:32 AM, Jochen Wiedmann at [EMAIL PROTECTED] wrote:
>
> >> this sort section starting on line 236
> >>
> >> @$rows = sort {
> >> $i = 0;
> >> do {
> >> $colNum = $sortCols[$i++];
> >> $desc = $sortCols[$i++];
> >> $c = $a->[$colNum];
> >> $d = $b->[$colNum];
> >> if (!defined($c)) {
> >> $result = -1;
> >> } elsif (!defined($d)) {
> >> $result = 1;
If neither is defined, shouldn't it return 0? It's not consistent
otherwise.
if (!defined $c || !defined $d) {
$result = defined $c <=> defined $d;
}
> >> } elsif ($c =~ /^\s*[+-]?\s*\.?\s*\d/ &&
> >> $d =~ /^\s*[+-]?\s*\.?\s*\d/) {
> >> $result = ($c <=> $d);
> >> } else {
> >> $result = $c cmp $d;
> >> }
> > Hi, Scott,
> >
> > I highly agree with you, that the RE that determines whether
> > a column contains a number should be changed. Any suggestions,
> > besides ^[+-]\d+$, possibly including floats?
> >
> > Thanks,
> >
> > Jochen
>
> I mailed Jochen back and indicated that I'd be posting this query to the
> MacPerl lists and to comp.lang.perl.misc as well in search of a better
> answer.. responses welcome. I'm stumped. :)
>
> *muttergrumbleregexes*
Using regexes to match numbers can get pretty messy.
BTW, in the current regex:
/^\s*[+-]?\s*\.?\s*\d/
only the first \s* is appropriate: according to Perl, " + 1" is not
numeric.
I make no guarantee of the correctness of this regex:
/^\s*[+-]?(?:\d+\.?\d*|\.?\d+)(?:[eE][+-]?\d+)?(?!\n)$/;
Ronald