ghostdog is correct, your statement below would never be true. For one, arrays start numbering at 0 , not 1, so fields[3] would be 54534.
Also, fields[3] wouldn't equal "1" or "5" , it would just start with that character. You should use a pattern match, if that's what you're trying to do. Something like this should work:
Did you actually try print()ing the content of @fields on each iteration while debugging? Your sample format does not suggest any field that has the content of exactly "1" so if that does not match "1" it is not really unusual.
try printing the $line value after reading from RR, see if anything is being read from the file. If so, try also printing the array after the split with:
print "line is $line\nFields are:\n". join ("\n", @fields) . "\n";
I am sorry i am replying your post, with new problem.
I am trying to get vlue of X positive and Negative. i am using array. It did not do the calculation part but i got out put
Cofficients: 2 5 1
Can not do the negetive calculations
Illegal division by zero at pgm4.pl line 31, <> line 1.
so i think some thing wrong in if statement i could not figuring out where is mistake. I will really apriciate it if someone show me the way.
$test0 = ($vol1**2-4*($vol*$vol2));
if (test0 <1)
{
print "Can not do the negetive calculations\n\n";
}
$test1 = (2*$vol);
if ($test1 <= 0)
{
print "Can not divide by zero\n\n";
}
$x = \(-$vol \+ sqrt\($test0\)\)/\(test1\);
$negative = (-$vol - sqrt($test0))/(test1);
if ($x = $negative)
{
print "$x";
exit;
}
else
{
print "$x\n $negative";
exit;
}
Thank you in Advance:confused: