Further to roboticus's reply: DespacitoPerl: Also note that the conditional in a statement like
    next if (my $start == 0);
is always true. A new lexical is created in the scope of the if-expression (update: see Update 2 below) and initialized as undefined. It does not exist outside of the if-expression. undef coerces to 0.

c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 999; print 'is it safe?' if (my $x == 0); " "my" variable $x masks earlier declaration in same scope at -e line 1. Use of uninitialized value in numeric eq (==) at -e line 1. is it safe?
Note also that there seem to be some warnings that you are ignoring.

Update 1: Just to be clear, this use of a lexical variable and other, similar uses of lexicals in what amount to dead scopes are all semantic errors.

Update 2: "A new lexical is created in the scope of the if-expression ..."   This is not true. Because the if-expression in
    next if (my $start == 0);
is a statement modifier (see perlsyn), no new scope is created. That (I finally realized) is the point of the "my" variable $x masks earlier declaration in same scope ... warning.

c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 999; print 'is it safe?' if (my $x = 1); print $x; " "my" variable $x masks earlier declaration in same scope at -e line 1. Found = in conditional, should be == at -e line 1. is it safe? 1
The assignment causes a change in the enclosing scope, so apparently it isn't safe, Dr. Szell!

Note that a statement of the non-statement-modifier form
    if (my $start == 0) { next; }
would create a new scope and would eliminate one warning message.

c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 999; if (my $x = 1) { print 'is it safe?'; } print $x; " Found = in conditional, should be == at -e line 1. is it safe? 999
Either way, however, the statement from the OPed code is still semantically problematic.

Update 3: Added link to the Statement Modifiers section in perlsyn.


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


In reply to Re: Delete lines if matched expression by AnomalousMonk
in thread Delete lines if matched expression by DespacitoPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.