Randy W. Sims wrote:
Jerry Preston wrote:
What needs to be changed in /(-?\d+\.?\d*)/ so that it also see number like .59?
This is why I like to recommend Regexp::Common. But...
use warnings; use Regexp::Common 'number'; $_ = '.'; /^$RE{num}{real}$/ and print "\"$_\" is a number.\n"; my $x = 1 if $_ < 5;
Outputs: "." is a number. "." isn't numeric in numeric lt (<) at ...
Regexp::Common considers an alone decimal point to be a number, while the Perl compiler does not. Did you know that? ;-)
Hrm, that's unfortunate :-/
Well, I'll still take this as an argument in favor of using modules like Regexp::Common. If your original regex were used: '(-?\d+(?:\.\d+)?)' and if it were used in more than one application, it would have to be changed everywhere. If, OTOH, Regexp::Common were used, we need only make the correction in one place and it is fixed everywhere.
BTW, I've posted the following to RT:
[cpan #6940] lone . (decimal) considered a match for $RE{num}{real} ------------------------------------------------------------------------- perl -MRegexp::Common=number -e 'print "oops\n" if "." =~ /$RE{num}{real}/'
This was pointed out to me by Gunnar Hjalmarsson in a thread on <[EMAIL PROTECTED]> ...
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>