I would not normally post such a simple question but: My current *debugging* code:
use strict; while (<DATA>) { chomp; my $input = $_; tr/$, +//d; if (/^[-]?\d+$/) { print "Acceptable: '$input' -> $_\n"; } elsif (/^[-]?\d+\.[\d]+$/) { ## problem print "Acceptable: '$input' -> ", int $_, "\n"; } else { print "Not acceptable: '$input' -> $_\n"; } } __DATA__ +30 -400 +20,0 -300.02 $ -50.1 -$ 500 - $ 60 + $ 30.
All the example data is acceptable. I don't need a one-regex-fits-all solution--readability is more important. Rounding is unnecessary. Blanks outside of the numeric component are allowable but should be eliminated from the results. I'm not sure how to correct *problem* expression to handle the last test case (and it may allow undesirable things I'm not aware of). Here is the output from the above code:
Acceptable: '-400' -> -400 Acceptable: '+20,0' -> 200 Acceptable: '-300.02' -> -300 Acceptable: '$ -50.1' -> -50 Acceptable: '-$ 500' -> -500 Acceptable: '- $ 60' -> -60 Not acceptable: ' + $ 30.' -> 30.
Thanks in advance for any help!

--Jim


In reply to Validating specific numeric input by jlongino

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.