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'.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|