Which is more efficient statement –> goto &fun($val) or fun($val) in perl ?
When to use which statement for better performance ?
Please let me know the answer !
Which is more efficient statement –> goto &fun($val) or fun($val) in perl ? When
Share
I think this is the wrong question to ask.
The form
fun($val)is the standard way to call another subroutine in perl.The form
goto &funcis normally used to transfer control to another sub while removing the current stack frame. In addition,@_is passed unaltered to the called routine.The removal of the stack frame means that
caller()will not see it, so that the&funcwill think that t was called by the caller of the routine which performed thegoto. It also means that performing a backtrace in the debugger will not reveal the routine performing thegoto.If you want to preserve the calling stack frame but pass control to a function with the current setting of
@_, then usereturn &func.The form
goto &func($val)is parsed as:This will likely give a
Can't find label ...error.Examples: