DarknessX has asked for the wisdom of the Perl Monks concerning the following question:
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?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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: negative numeric strings with STDIN
by The Mad Hatter (Priest) on May 17, 2003 at 20:02 UTC | |
|
Re: negative numeric strings with STDIN
by chromatic (Archbishop) on May 17, 2003 at 20:04 UTC |