Just out of curiosity, a couple more variations. Note that Scalar::Util::looks_like_number() thinks things like  +1  -1  2e3 look like numbers that you may not want to accept.

c:\@Work\Perl\monks>perl -wMstrict -le "use Scalar::Util qw(looks_like_number); ;; use Data::Dump qw(pp); ;; for my $n ( undef, '', '.', '..', '.1.', '1..1', 0, '0', '0.', '0.0', '.0', '000.000', 1, '1', '1.', '1.0', '001.100', '+1', '-1', '2e3', ) { printf qq{%s %s like num \n}, pp($n), looks_like_number($n) ? 'looks' : 'does not look'; } " undef does not look like num "" does not look like num "." does not look like num ".." does not look like num ".1." does not look like num "1..1" does not look like num 0 looks like num 0 looks like num "0." looks like num "0.0" looks like num ".0" looks like num "000.000" looks like num 1 looks like num 1 looks like num "1." looks like num "1.0" looks like num "001.100" looks like num "+1" looks like num -1 looks like num "2e3" looks like num c:\@Work\Perl\monks>perl -wMstrict -le "sub unsigned_real { return defined($_[0]) && $_[0] =~ m{ \A (?: \d+ (?: [.] \d*)? | \d* [.] \d+) \z }xms ; } ;; use Data::Dump qw(pp); ;; for my $n ( undef, '', '.', '..', '.1.', '1..1', '+1', '-1', '2e3', 0, '0', '0.', '0.0', '.0', '000.000', 1, '1', '1.', '1.0', '001.100', ) { printf qq{%s %s real \n}, pp($n), unsigned_real($n) ? 'looks' : 'does not look'; } " undef does not look real "" does not look real "." does not look real ".." does not look real ".1." does not look real "1..1" does not look real "+1" does not look real -1 does not look real "2e3" does not look real 0 looks real 0 looks real "0." looks real "0.0" looks real ".0" looks real "000.000" looks real 1 looks real 1 looks real "1." looks real "1.0" looks real "001.100" looks real
If the speed of any of these is acceptable, you will, of course, develop your own Test::More test suite(s). (But you'll want to do | you've already done that in any case. :)


Give a man a fish:  <%-{-{-{-<


In reply to Re^3: 4x faster now! (updated) by AnomalousMonk
in thread Syntax Perl Version support $c = () = $a =~ /\./g by h2

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.