in reply to Re: Messing with @_
in thread Messing with @_

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?

Replies are listed 'Best First'.
Re^3: Messing with @_
by kyle (Abbot) on May 29, 2008 at 22:24 UTC

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

Re^3: Messing with @_
by jethro (Monsignor) on May 29, 2008 at 22:28 UTC
    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.