in reply to Re^2: whats wrong with this break ?
in thread whats wrong with this break ?

Have you considered using else instead of break?
The break is going to make it harder to maintain, unless you heavily comment your code. Especially as this is not what you are actually doing with these lines but simplied to illistratrate your point, which will effective hide the break within your code.
Using an else there instead will slow your script slightly for the additional check on every line, though the increase in maintainability might be well worth the cost.

Replies are listed 'Best First'.
Re^4: whats wrong with this break ?
by GrandFather (Saint) on Sep 17, 2010 at 22:21 UTC

    Actually I'd argue strongly in the other direction! The OP has two separate loops for handling different parts of a parsing process. At most a comment at the start of each is all that is required to make that clear. About the only change I'd make is to change the if statement into a statement modifier:

    last if /^2/;

    to make the last easy to see.

    Aside from making the code harder to maintain because you are conflating two different processing phases into one statement, using a needless else increases code nesting and makes it harder to follow code flow. I find early exits (such is indicated above) make the normal flow of code much easier to see.

    True laziness is hard work