I am curious as to why you even want/need to do this?

It might be that you are asking either a home work question or the wrong question for a practical application. I am having trouble understanding your application that requires this distinction between C data types.

If you want to know if some string is valid in a numeric context, let Perl figure it out by simply adding "zero" to that number. If that is not a valid number, eg. "1.1.1", you will get a warning error message.

How to intercept this warning message and do something about it is different than what you have asked. Anyway some very simple code is attached that will generate a warning message if a "number" is not a "number"...

#!/usr/bin/perl use strict; use warnings; $| =1; #turn off STDIO buffering #this causes the error messages to STDERR #to appear closer to the standard print stuff my @numbers = qw(1 -1 123.1 0.1 1E6 ); foreach my $number (@numbers) { print "$number: \t", $number+0,"\n"; } print "now weirder stuff...\n\n"; @numbers = qw (1.1.1 4-1-1 --2); foreach my $number (@numbers) { print "$number: \t", $number+0,"\n"; } __END__ OUTPUT: 1: 1 -1: -1 123.1: 123.1 0.1: 0.1 1E6: 1000000 now weirder stuff... Argument "1.1.1" isn't numeric in addition (+) at C:\PerlTemp\testnume +ric2.pl line 19. 1.1.1: 1.1 Argument "4-1-1" isn't numeric in addition (+) at C:\PerlTemp\testnume +ric2.pl line 19. 4-1-1: 4 Argument "--2" isn't numeric in addition (+) at C:\PerlTemp\testnumeri +c2.pl line 19. --2: 0

In reply to Re: How do I determine with a regular expression whether a scalar is a number/whole/integer/float? by Marshall
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.