If you're going to use a regexp to parse a number (which seems to me to be the right approach as well), the best bet would be to use Conway's Regexp::Common module (actually Regexp::Common::number but that link dumps you into a page of results) which does this for you (and one would assume that it gets all the hairy bits right).
use Regexp::Common qw/number/; sub make_num { return $_[0] =~ /(^$RE{num}{real}$)/ ? $1 : undef; }
tweaked: s/is_num/make_num/ and changed the return value, in order to be more in line with the original question.
In reply to Re:x2 Parse float from string (use Regexp::Common)
by grinder
in thread Parse float from string
by gryphon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |