Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found