Can't locate loadable object for module Scalar::Util::Numeric

Scalar::Util::Numeric is an XS module, which means it must always be compiled against whatever version of Perl is on the user's machine. So your requirement

I don't want to require users to install anything - just git clone and it should work.

is the first thing I would question. Yes, even you can use CPAN, and so can your users.

Yes, there is Scalar::Util::Numeric::PP and you could use this for your Option 1. But then the problem becomes maintenance: You'd have to always make sure to update your module if there are changes or fixes to the upstream module - I guess one could call this a variation of DRY. Similar issue with your Option 2: Sure, you can reinvent the wheel, but then remember to write enough tests to cover all edge and corner cases etc.

Though this is just a variation of the above, another option might be to take the regexes produced by Regexp::Common::number and integrate those into your code. This has the same problem as above, but at least it's a bit less code to copy over...

See also the FAQ How do I determine whether a scalar is a number/whole/integer/float?

By the way, in regards to the title of the question, there is an important distinction sometimes missed by people that the question should be "does this string look like a integer/float", and not "does this Perl scalar hold a number or a string", because oftentimes Perl scalars can be both a number and a string depending on what context they're used in, and therfore, in Perl, this is not the right question to ask. (The only exception might be when writing a data serialization tool, and even those often run into trouble in making that distinction.)


In reply to Re: Portable way of checking if a scalar is a number / integer / float by haukex
in thread Portable way of checking if a scalar is a number / integer / float by bishop729

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.