http://qs321.pair.com?node_id=181975


in reply to Re: GOTO considered (a necessary) evil?
in thread GOTO considered (a necessary) evil?

But a redo (just like next and last is just a glorified goto.

I consider this statement blatently false and missleading.

This typo generates an error...

perl -le 'BAR: print 1; BAZ: for (2..3) {print; redo BAR; }'

This typo causes an infinite loop...

perl -le 'BAR: print 1; BAZ: for (2..3) {print; goto BAR; }'

(Updated to be less pedantic... the point is, goto is for arbitrary jumping, redo is for controlled jumping to the begining of a loop. Could you live w/o redo if you had goto? yes. Does that mean you should just use goto and not bother with redo? no.)

Replies are listed 'Best First'.
Re: Re: Re: GOTO considered (a necessary) evil?
by clintp (Curate) on Jul 16, 2002 at 02:19 UTC
    But a redo (just like next and last is just a glorified goto.
    I consider this statement blatently false and missleading.
    • redo FOO will only work if the label FOO exists at some surrounding loop block

    I consider this statement to be inaccurate and not quite pendantic enough for flaming someone! Observe:

    sub bar { no warnings 'exiting'; redo FOO; } FOO: { print "Hey!"; bar(); }
    The redo worked and the label did not exist in a surrounding loop block.
Re: GOTO considered (a necessary) evil?
by Abigail-II (Bishop) on Jul 16, 2002 at 09:25 UTC
    This typo generates an error...
    perl -le 'BAR: print 1; BAZ: for (2..3) {print; redo BAR; }'
    This typo causes an infinite loop...
    perl -le 'BAR: print 1; BAZ: for (2..3) {print; goto BAR; }'
    That's a pretty weak example, because if you omit the typos, both
    perl -le 'BAR: print 1; BAZ: for (2..3) {print; redo BAZ; }'
    and
    perl -le 'BAR: print 1; BAZ: for (2..3) {print; goto BAZ; }'
    behave identically - looping infinitely.

    Abigail