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

Thanks. I had not considered that the IF criteria could be met in more than one way. I have included the recommended next unless length $_; after the chomp $_; however the same error is still returned. I've also tried next if (/^\s+$/); to no avail.

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

    Then the next step is to put a print statement immediately before line 15 (line 16 now that you added the next unless length line). Print the raw line, and also some of the variables holding various splits and matches. Verify that things look like you expect them to. That will help you to spot the case that you're not handling correctly.


    Dave

      Inspecting and printing @array, @F and the raw-line all show that the final entry is a blank line. The split handles all lines containing content as intended, and these errors only occur when it reaches the end of any given input file - but skipping empty lines still does not appear to work oddly.

        /^\s+$/ needs one or more to skip

        Try /^\s*$/

        poj
        Then you are probably not doing the right thing to skip "empty" lines. Or the line in question might not be really empty (there could be a new line character or some spaces that you can't see).

        How do you skip empty lines? Perhaps you should remove spaces before (unless your lines have necessary spaces), or detect that the line doesn't have any character other than spaces.

        We can't say for sure, not having seen your input, but it could be something like this:

        next unless /\S/;
        which will skip the line unless it contains any non-space character.