Do you know that...
Yes, it's documented in perlapi. I didn't assume that would be a concern for the OP.
The old pure-Perl version of Scalar::Util has a pure-Perl version of looks_like_number, which includes the following code:
return 1 if ( $] >= 5.008 and /^(Inf(inity)?|NaN)$/i ) or ( $] >= 5.006001 and /^Inf$/i );
So if we wanted to eliminate that behavior, we could either copy/paste and modify the entire pure-Perl version from an old version of Scalar::Util (but it has issues with '0 but true'), or use the modern version of Scalar::Util::looks_like_number like this:
sub looks_like_finite_number { my $candidate = shift; return 0 if ! looks_like_number( $candidate ); return 0 if ( $] >= 5.008 and $candidate =~ /^(Inf(inity)?|NaN)$/i) or ( $] >= 5.006001 and $candidate =~ /^Inf$/i ); return 1; }
Or, in perlfaq4 there is a series of regexes given for determining if one is looking at a number under the section, "How do I determine whether a scalar is a number/whole/integer/float? It's not pretty, and that FAQ answer has even changed over the years; it used to use a bunch of "if" statements. Now it uses given/when. *sigh*
Dave
In reply to Re^3: storage of numbers
by davido
in thread storage of numbers
by ostra
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |