<?xml version="1.0" encoding="windows-1252"?>
<node id="288" title="perlfunc:goto" created="1999-08-24 18:42:55" updated="2005-08-12 19:30:53">
<type id="119">
perlfunc</type>
<author id="114">
gods</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
goto - create spaghetti code

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
goto 
&lt;FONT SIZE=-1&gt;LABEL&lt;/FONT&gt;

&lt;P&gt;
goto 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt;

&lt;P&gt;
goto &lt;CODE&gt;&amp;amp;NAME&lt;/CODE&gt;

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="description">

&lt;P&gt;
The &lt;CODE&gt;goto-LABEL&lt;/CODE&gt; form finds the statement labeled with 
&lt;FONT SIZE=-1&gt;LABEL&lt;/FONT&gt; and resumes execution there. It may not be used
to go into any construct that requires initialization, such as a subroutine
or a &lt;CODE&gt;foreach&lt;/CODE&gt; loop. It also can't be used to go into a construct that is optimized away,
or to get out of a block or subroutine given to [perlfunc:sort|sort()]. It can be used to go almost anywhere else within the dynamic scope,
including out of subroutines, but it's usually better to use some other
construct such as [perlfunc:last|last] or [perlfunc:die|die()]. The author of Perl has never felt the need to use this form of [perlfunc:goto|goto] (in Perl, that is--C is another matter).

&lt;P&gt;
The &lt;CODE&gt;goto-EXPR&lt;/CODE&gt; form expects a label name, whose scope will be resolved dynamically. This
allows for computed [perlfunc:goto|goto]s per 
&lt;FONT SIZE=-1&gt;FORTRAN,&lt;/FONT&gt; but isn't necessarily recommended if you're
optimizing for maintainability:

&lt;P&gt;
&lt;PRE&gt;    goto (&amp;quot;FOO&amp;quot;, &amp;quot;BAR&amp;quot;, &amp;quot;GLARCH&amp;quot;)&amp;#091;$i&amp;#093;;
&lt;/PRE&gt;
&lt;P&gt;
The &lt;CODE&gt;goto-&amp;amp;NAME&lt;/CODE&gt; form is highly magical, and substitutes a call to the named subroutine for
the currently running subroutine. This is used by
&lt;CODE&gt;AUTOLOAD&lt;/CODE&gt; subroutines that wish to load another subroutine and then pretend that the
other subroutine had been called in the first place (except that any
modifications to &lt;CODE&gt;@_&lt;/CODE&gt; in the current subroutine are propagated to the other subroutine.) After
the [perlfunc:goto|goto], not even [perlfunc:caller|caller()]
will be able to tell that this routine was called first.

&lt;HR&gt;
</field>
</data>
</node>
