http://www.perlmonks.org?node_id=833064


in reply to Re^3: cross scope gotos?
in thread cross scope gotos?

> I think that's (currently) an over statement:

nope, while has a proper block but not a proper "frame" like foreach or subs.

(I read somewhere that foreach has internally a frame, but no time to search now...)

But the confusion is understandable, that's why I started the thread.

Cheers Rolf

Replies are listed 'Best First'.
Re^5: cross scope gotos?
by ikegami (Patriarch) on Apr 06, 2010 at 16:36 UTC

    Counter-example:

    perl -le"goto loop; $x=0; if( $x ){ for(;;){ loop: print 'hi' } }"

    Update: Ah, you did say foreach

    >perl -le"goto loop; $x=0; if( $x ){ for(1){ loop: print 'hi' } }" Can't "goto" into the middle of a foreach loop at -e line 1.

    Mind you, it's not really related to stack frames. Any required frame is created by goto. Since it's an explicit check for OP_ENTERITER, it appears more of a question of there not being any sensible way of initialising the iterator of the iterated loop into which you are jumping.

    /* push wanted frames */ if (*enterops && enterops[1]) { OP * const oldop = PL_op; ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1; for (; enterops[ix]; ix++) { PL_op = enterops[ix]; /* Eventually we may want to stack the needed arguments * for each op. For now, we punt on the hard ones. */ if (PL_op->op_type == OP_ENTERITER) DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loo +p"); CALL_FPTR(PL_op->op_ppaddr)(aTHX); } PL_op = oldop; }

    Update: Improved phrasing of last paragraph and added supporting code.

      Well I don't know anymore where I read the word "frame" in connection with foreach-loops.

      The glossary of the docs is often far too fuzzy to justify a long discussion...

      Anyway grepping through the docs produced

      perldiag.pod: (P) The foreach iterator got called in a non-loop context frame.

      (I didn't say "call frame")

      But the C code is quite hard for me too understand without more conceptual basics... which are fuzzy ...

      Cheers Rolf