in reply to Re^2: Trouble skipping lines using Perl
in thread Trouble skipping lines using Perl

I went with

next if ($chromosome =~ "chrM");

Also note that  $chromosome =~ "chrM" matches if  "chrM" is found anywhere in the  $chromosome string:

c:\@Work\Perl\monks>perl -wMstrict -le "my $chromosome = 'foo xx chrM yy bar'; print 'found a chrM' if $chromosome =~ 'chrM'; " found a chrM
This is because you no longer anchor the match to the start of the string (as you do in the code in the OP) with the  ^ match anchor regex operator. The match  /^chrM/ would IMHO be better for what you seem to want.

Another point is that the data posted in the OP has a leading space or spaces in some cases. Leading whitespace will cause the  /^chrM/ match to fail. If leading whitespace may be present in real data, I would recommend something along the lines of  /^\s*chrM/ instead.


Give a man a fish:  <%-{-{-{-<

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

    Ah ok,

    I'm following you, thanks very much :)