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

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

Try /^\s*$/

#!perl use strict; use warnings; 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 "$!"; <IN> for (1..45); # skip 45 lines while (<IN>) { next unless /\S/; # skip blanks chomp $_; my @F = split ' ', $_; my @array = split m[[:,/]+], $F[9]; my $check = index $F[4],','; if ($check == -1) { my $ratio = $array[3] / $array[4]; print OUT join "\t",@F[0,1,3,4],$ratio,$array[4]; print OUT "\n"; } elsif ($check > 0) { my @allele = split ',', $F[4]; my $ratio1 = $array[3] / $array[5]; my $ratio2 = $array[4] / $array[5]; print OUT join "\t",@F[0,1,3],$allele[0],$ratio1,$array[5]; print OUT "\n"; print OUT join "\t",@F[0,1,3],$allele[1],$ratio2,$array[5]; print OUT "\n"; } print $_; } }
poj

Replies are listed 'Best First'.
Re^6: Illegal division by zero error
by TJCooper (Beadle) on Feb 01, 2016 at 18:16 UTC
    Thank you. This seems to have solved it. I didn't realise that /^\s+$/ relied on their being 1 or more.
      OK, have a look at quantifiers in perlre