in reply to Breaking out of an 'if'

One more old chestnut solution...

if ($some_condition){{ &some_stuff(); last if $another_condition; &some_more_stuff; }}

... though I don't tend to use this since I find the extra braces to be too subtle when rereading the code (i.e. someone, ok me, removes them since they look redundant which then changes the sematics of the surrounding code).

Replies are listed 'Best First'.
Re^2: Breaking out of an 'if'
by thor (Priest) on Apr 14, 2005 at 23:29 UTC
    I find the extra braces to be too subtle when rereading the code
    Whitespace is your friend:
    if ($some_condition){ { #heck, even comment the bare block &some_stuff(); last if $another_condition; &some_more_stuff; } }

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      Whitespace is your friend:

      That helps some, but to me it still looks like a cut/paste error without a comment. If you have to comment, I'm not sure what the point is (i.e. use something like one of the other solutions which is more self-describing), but of course YMMV. Now if you use this all of the time in the code you maintain then that's probably fine since it becomes an idiom (i.e. a programmer will see this code multiple times and realize it isn't a typo). I find that I rarely if ever do this so it would become more of a hazard than anything else to me...