After numerous supersearches, I still couldn't come up with an answer to my question. I'm in precalc, so to make life easy I wrote up a quick little quadratic equation solver. My question lies not in that however, but rather in why I'm having issues with numeric and nonnumeric strings. my code is quite simple,
print "A?="; chomp(my $a=<STDIN>); print "B?="; chomp(my $b=<STDIN>); #get Ax**2+Bx+C values print "C?="; chomp(my $c=<STDIN>); my $ans1=(($b x -1)+sqrt(($b**2) - 4 x $a x $c)) / (2 x $a) or die "Un +real answer!\n"; #note the ugliness of ($b x -1), any better way to g +et -$b? my $ans2=(($b x -1)-sqrt(($b**2) - 4 x $a x $c)) / (2 x $a); print "Answers: $ans1 AND $ans2\n\n";
With warnings, I get errors which look like Argument "" isn't numeric in addition (+) at ./quad.pl line 11, <STDIN> line 3.. Without warnings, of course I don't get these. So, being a competent perl programmer, I want to use warnings, or figure out why I can't. How do I get numeric strings from STDIN?

In reply to negative numeric strings with STDIN by DarknessX

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.