http://www.perlmonks.org?node_id=997684


in reply to @_ & @ARGV

The @_ parameter to a subroutine gets populated at RUN TIME (or the time the subroutine gets called), with whatever is passed to it at that time.

In tHe first call, you pass @ARGV to the 'formlist' sub.
This returns an ANONYMOUS sub that is assigned to $arguments.
You call the Anonymous sub, pasisng it "Command Line", which, as you can see is received and printed just fine.

Perhaps we can explain it better if you tell us what you were expecting, and why.

In case you were unaware, you created a "closure" around @list, preserving it's value.

             I hope life isn't a big joke, because I don't get it.
                   -SNL

Replies are listed 'Best First'.
Re^2: @_ & @ARGV
by Athanasius (Archbishop) on Oct 07, 2012 at 15:12 UTC

    Closures are discussed in perlsub, but the best explanation of closures that I know of is in Chapter 3 of Higher-Order Perl by Dominus, available free online at http://hop.perl.plover.com/.

    Hope that helps,

    Athanasius <°(((><contra mundum

Re^2: @_ & @ARGV
by tobyink (Canon) on Oct 07, 2012 at 15:19 UTC

    Further, only lexical variables can be closed over. @_ is not a lexical variable (it's not declared with my) so can't be closed over.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^2: @_ & @ARGV
by dushyant (Acolyte) on Oct 07, 2012 at 17:41 UTC

    Thanks for the replies guys, now I got it. I was expecting the value of @_ will remain same (“-w”) throughout the code. But for subroutine formatlist the value of @_ is “-w” and for anonymous subroutine @_ is “Command Line”. I removed the last line  &$arguments(‘Command Line’) from above code, and got “-w out return” printed.