in reply to Re: Parse float from string
in thread Parse float from string

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.



print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'