A couple of comments.

The code you quote from the FAQ and the code you wrote for testing purposes are not equivalent at all. The FAQ's code will try each regex in turn, whereas your code will skip all the subsequent tests as soon as one of them is successful. So that if you test for example with -1 or 1.3, the first regex (has non digits) will match and no other test will be carried out (because they are all in an else branch of the first condition). In brief, your algorithm is wrong.

Then you also have an error in your update:

my @numbers = qw(1, 1.0, 123.1, 0.1);
is wrong because you should not put commas in the qw// operator (see http://perldoc.perl.org/perlop.html#Quote-Like-Operators). With the above syntax, the first elements of @numbers are "1,", "1.0,", etc., so that all your elements except the last have at least one non digit, the trailing comma. You should write:
my @numbers = qw(1 1.0 123.1 0.1);

In reply to Re: How do I determine with a regular expression whether a scalar is a number/whole/integer/float? by Laurent_R
in thread [SOLVED] How do I determine with a regular expression whether a scalar is a number/whole/integer/float? by thanos1983

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.