TJCooper has asked for the wisdom of the Perl Monks concerning the following question:
I have a basic script which parses and processes a set of .tmp input files:
my $extension = '.txt'; my @files = glob("*.tmp"); for my $file (@files) { open IN, '<', $file or die "$!"; $file =~ s/\..*//; my $outfile = $file.$extension; open OUT, '>', $outfile or die "$!"; while (<IN>) { next unless $. > 45; chomp $_; our(@F) = split(' ', $_, 0); @array = split(m[[:,/]+], $F[9], 0); $check = index($F[4],','); if ($check == '-1') { $ratio = $array[3] / $array[4]; print OUT "$F[0]\t$F[1]\t$F[3]\t$F[4]\t$ratio\t$array[4]\n +"; } elsif ($check > 0) { @allele = split(',', $F[4]); $ratio1 = $array[3] / $array[5]; $ratio2 = $array[4] / $array[5]; print OUT "$F[0]\t$F[1]\t$F[3]\t$allele[0]\t$ratio1\t$arra +y[5]\n$F[0]\t$F[1]\t$F[3]\t$allele[1]\t$ratio2\t$array[5]\n"; } } }
However upon running it, I am receiving the error:
Illegal division by zero at /file/pathway/script.pl line 15 <IN> line 37864Why is this occurring and how can it be fixed?
Line 37864 is the final line+1 in the first input file (i.e. it's attempting to process an empty line), so I have a feeling that it is due to the fact that in a couple of instances I am splitting one input line into two output lines (see Line 22) and this is offsetting $. but I am not sure.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Illegal division by zero error
by davido (Cardinal) on Feb 01, 2016 at 16:31 UTC | |
by TJCooper (Beadle) on Feb 01, 2016 at 16:46 UTC | |
by davido (Cardinal) on Feb 01, 2016 at 16:50 UTC | |
by TJCooper (Beadle) on Feb 01, 2016 at 17:12 UTC | |
by poj (Abbot) on Feb 01, 2016 at 18:02 UTC | |
| |
by Laurent_R (Canon) on Feb 01, 2016 at 18:04 UTC | |
|
Re: Illegal division by zero error
by Corion (Patriarch) on Feb 01, 2016 at 16:28 UTC | |
by TJCooper (Beadle) on Feb 01, 2016 at 16:32 UTC | |
by Corion (Patriarch) on Feb 01, 2016 at 16:38 UTC | |
by TJCooper (Beadle) on Feb 01, 2016 at 16:51 UTC | |
by Corion (Patriarch) on Feb 01, 2016 at 16:56 UTC | |
|