Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How does next label work?

by moritz (Cardinal)
on Jan 06, 2013 at 10:04 UTC ( #1011869=note: print w/ replies, xml ) Need Help??


in reply to How does next label work?

I thought next is just another way to say goto

Well, it's not. You can see that next and goto compile to different ops internally:

$ perl -MO=Concise -e 'X: next X' 4 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(X: main 1 -e:1) v:{ ->3 3 <"> next("X") v ->4 -e syntax OK $ perl -MO=Concise -e 'X: goto X' 4 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(X: main 1 -e:1) v:{ ->3 3 <"> goto("X") v ->4 -e syntax OK

Another difference is this warning here:

$ perl -wE 'sub f() { next X }; X: for (1) { f }' Exiting subroutine via next at -e line 1.

which you don't get with goto. And of course the fact that the code above terminates, but doesn't if you replace 'next' with 'goto'.


Comment on Re: How does next label work?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2015-07-01 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (22 votes), past polls