in reply to Illegal division by zero error

Have you inspected line 15 in your code? Is there a division happening in line 15?

What steps have you taken to verify that the divisor in line 15 is not zero? Have you printed it out?

Replies are listed 'Best First'.
Re^2: Illegal division by zero error
by TJCooper (Beadle) on Feb 01, 2016 at 16:32 UTC

    Yes, line 15 is a division:

    $ratio = $array[3] / $array[4];

    The division it is attempting is essentially "zero" because it's attempting to process an empty line after the end of the file.

    I am not sure what is actually the issue - although I think it may be the issue I specified in the OP - if so, i'm not entirely sure how to compensate for the splitting of lines. I did try to essentially offset $. myself by subtracting '1' from it everytime the elseif loop criteria is met but the error is still returned.

      So you have ascertained that the error happens because you enter that block of code but $array[4] contains a value that Perl interprets as zero.

      Maybe you don't want to enter that block if $array[4] contains a value that Perl interprets as zero? Maybe you want to prevent processing invalid lines that leave invalid values in @F?

      You have not shown examples of valid and problematic lines, so we can only guess and trace the path of execution backwards from where the error happens. If you tell us what you want to avoid, or for what kind of lines the error happens, maybe we can better find a solution with you.

      Maybe you want to skip processing empty lines?

        I was not originally aware that this could be caused by blank lines (because there are no blank lines at the end of the input files). I've tried skipping blank lines as suggested above, but this has not remedied the error. Currently, the error currently only occurs when the script attempts to process past the final line of the input. I can't figure out why it's attempting to do this in the first place.