in reply to Trouble skipping lines using Perl

You've been given complete answers to your question, but I would comment that:

So the code could be made significantly shorter (and probably slightly faster) as follows, without losing any clarity:

while (my $line = <FILE>) { next if $. == 1; next if $line =~ /^\s*chrM/; my ($chromosome, $nmreads, $mutants) = (split "\t", $line)[0, 8, 9 +]; # note: $chromosome is not used, this could be simplified further my $totalreads = $nmreads + $mutants; print ("$nmreads $mutants $totalreads\n"); }
I'm not saying that your code was bad, it wasn't, but I'm just trying to show some opportunities for improvement.

Update: Fixed a typo (s/loosing/losing/), thanks to 1nickt for letting me know.

Replies are listed 'Best First'.
Re^2: Trouble skipping lines using Perl
by LeBran (Initiate) on Nov 22, 2017 at 11:06 UTC

    Hi,

    Yeah, I can see the logic there, is certainly a lot neater and the time saving aspect (though probably minor in this case) is something I should try to remember

    I did actually use $chromosome and $chrpos in another print statement later, I just hadn't reached that part yet because the next if loop was bugging me haha :D

    Thanks for the help