in reply to Re: Illegal division by zero error
in thread Illegal division by zero error

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.

Replies are listed 'Best First'.
Re^3: Illegal division by zero error
by Corion (Patriarch) on Feb 01, 2016 at 16:38 UTC

    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.

        There are many ways that the relevant code block could be entered. Maybe you want to print out the line that is processed, together with the values stored in @array and the values stored in @F to determine what the line looks like instead of guessing that it must be an empty line?