在帮助您解决问题的同时,我将向您展示一些最佳实践...
#!/usr/bin/perl
use strict; # strict/warnings helps detect lots of bugs and logic issues,
use warnings; # so always use them
use Math::Complex; # WHITESPACE IS YOUR FRIEND
#quadraticEq - quadratic equation with parameters a ,b ,c
sub quadraticEq{
# Shift out your subroutine variables one at a time, or assign them to a list.
my ($a, $b, $c) = @_;
print "\nx1= ",
($b*$b-sqrt($b*$b-4*$a*$c))/(2*$a), # You're wrong on your formula btw
"\nx2= ",
($b*$b+sqrt($b*$b-4*$a*$c))/(2*$a);
}
print 'Enter Numbers: ';
# Perl only supports reading in a line at a time, so... if you want all your
# inputs on one line, read one line.
# EDIT: That's not strictly true, since you can change the input record separator,
# but it's just simpler this way, trust me.
my $line = <>;
# Then you can split the line on whitespace using split.
my @coefficients = split /\s+/, $line;
# You should check that you have at least three coefficients and that they
# are all defined!
quadraticEq(@coefficients);