in reply to Match number >= 0 and <1
my ($num) = $_num =~ /^(0*\.\d+)$/
In any case, it's probably better if you first check if it's a number, then check if it's in range. It makes the code easier to read, more maintainable and less error prone.my $num = ($_num =~ /^(0+(?:\.\d+)?|\.\d+)$/) ? 0+$1 : undef;
my ($num) = $_num =~ /^(...)$/ undef $num if defined $num && ($num < 0 || $num >= 1);
Update: oops, it didn't match just plain '0'.
|
---|