On 02/19/04 23:21, James Edward Gray II wrote:On Feb 19, 2004, at 9:22 PM, R. Joseph Newton wrote:I don't know, Rob. I would be interested in hearing of any real-world problem thatI believe the text book example is a language that lacks support for something like Java's "finally" block. A goto can guarantee you get to the code that must be executed, no matter the outcome of the current block.
would demand this.
James
One example of a legitimate use of goto from perlsub:
Many "AUTOLOAD" routines load in a definition for the requested subroutine using eval(), then execute that sub- routine using a special form of goto() that erases the stack frame of the "AUTOLOAD" routine without a trace. (See the source to the standard module documented in AutoLoader, for example.)
The version of goto() your are talking about here, goto &NAME, is a little different from your standard goto(). From 'perldoc -f goto':
The "goto-&NAME" form is quite different from the other forms
of "goto". In fact, it isn't a goto in the normal sense at
all, and doesn't have the stigma associated with other gotos.
Instead, it exits the current subroutine (losing any changes
set by local()) and immediately calls in its place the named
subroutine using the current value of @_. This is used by
"AUTOLOAD" 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 @_ in the current
subroutine are propagated to the other subroutine.) After the
"goto", not even "caller" will be able to tell that this rou-
tine was called first.
NAME needn't be the name of a subroutine; it can be a scalar
variable containing a code reference, or a block which evalu-
ates to a code reference.
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>