I use this routine that I slightly changed from one posted here long ago, I think by Vroom, that I cannot find now in the site. It seems to work on those tests.
#!/usr/bin/perl -wl
use strict;
my @nums = qw(
0e0
0
+0
-0
1.
0.14
.14
1.24e5
24e5
-24e-5
2.3.
2.3.4
1..2
);
for (@nums) {
print "ok: ", $_ if is_a_number($_);
}
###############
sub is_a_number {
###############
my $var = $_[0];
$var =~ s/^\s+//;
$var =~ s/\s+$//;
if ($var =~ /^([+-]?)(\d+\.|\.\d+|\d+)\d*([Ee]([+-]?\d+))?$/) {
return(1)
} else {
return(0)
}
}
Regards,
Roberto