Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Passing array to a subroutine

by haukex (Monsignor)
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 having an uproarious good time at the Monastery: (4)
As of 2017-11-25 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (355 votes). Check out past polls.

    Notices?