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

Ah, thank you,

So presumably  next if ($_ = /^chrM/); would also be correct?

Cheers

Replies are listed 'Best First'.
Re^5: Trouble skipping lines using Perl
by AnomalousMonk (Archbishop) on Nov 21, 2017 at 17:23 UTC
    So presumably  next if ($_ = /^chrM/); would also be correct?

    No! The  $_ = /^chrM/ expression matches the regex against  $_ (update: by default, since the  // match is not explicitly bound to any other scalar by a  =~ binding operator) and then assigns the result of the comparison | match to  $_ (which at least gives  $_ some defined value, so I guess it's not all bad :) Matching against  $_ (or any other scalar variable) is only semantically correct if that variable has first been given some meaningful value as in a  while (<FILE>) { ... } loop. Stick to
        next if ($line =~ /^chrM/);


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