in reply to Messing with @_

I needed a while to find out what happened. Nice trick.

To make it easier for other readers: The difference is that in the No_Side_Effects version @_ gets overwritten thereby destroying the aliasing between the function arguments and @_.

I can't see any gotchas, but that doesn't mean much.

Replies are listed 'Best First'.
Re^2: Messing with @_
by monarch (Priest) on May 29, 2008 at 22:09 UTC
    I know I'm going to appear a little thick with this post, but how does a sub-routine magically adopt the @_ arguments from the parent routine? I thought @_ was local to each sub-routine?

      That happens if you call the sub with an ampersand and without parentheses. This is documented in perlsub.

      When you call a function without braces i.e. &func instead of &func(), a shortcut happens.

      In the words of 'man perlsub':

      If a subroutine is called using the "&" form, the argument list is optional, and if omitted, no @_ array is set up for the subroutine: the @_ array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid.