Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: cross scope gotos?

by LanX (Canon)
on Apr 06, 2010 at 15:19 UTC ( #833054=note: print w/ replies, xml ) Need Help??


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

> Basically anywhere in the current program that hasn't been optimised away:

not that easy!

perl -e' goto INTO; print "Start"; for $i (0..9) { INTO: print "STOP"; };' Can't "goto" into the middle of a foreach loop at -e line 4.

You can't jump to a label out of the current or previous frames!

see Re^3: cross scope gotos? and goto

Cheers Rolf


Comment on Re^2: cross scope gotos?
Download Code
Re^3: cross scope gotos?
by BrowserUk (Pope) on Apr 06, 2010 at 16:04 UTC
    You can't jump to a label out of the current or previous frames!

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

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

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      > 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

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://833054]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2014-07-30 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls