Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Passing array to a subroutine

by haukex (Abbot)
on Sep 13, 2017 at 13:51 UTC ( #1199305=note: print w/replies, xml ) Need Help??


in reply to Passing array to a subroutine

1nickt gave you a solution, just to explain what's going on: In Perl, arguments to subroutines/methods are by default flattened into one big list. So for example, if you have an array my @x = ('y', 'z'); and a function call like func(a=>@x, b=>'c');, and considering that the => is just a special kind of comma, what the function ends up getting called with is ('a', 'y', 'z', 'b', 'c'). This flattening is described in perlsub. To learn more about references, which are scalars and won't get flattened, see perlreftut.

A few minor updates for clarification.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1199305]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-02-21 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (274 votes). Check out past polls.

    Notices?