I have some questions regarding array arguements passing for Perl Function.
If @array contains 2 items , arguements passing would be like Code_A.
But what if @array needs to add in more items, the rest of the code like $_[some number] will have to be modified as well (highlighted in red), which is very troublesome, just like in Code_B where 1 more item is added to @array. Is there an easier way to overcome this problem ?
There is a couple of ways to tackle the problem. Keep in mind when you pass arguments to a function they all become one big list. So either you pass the strings as the first arguments and the array last:
Thanks for the advice, but what's the below code trying to do ?
And what does @_ represent ?
And what if there are 2 array list ? Which method would be better ?
@_ is the automagically created array containing all calling parameters (the array that you use when you access $_[x]). And if there's more than one array to pass around, refs are definitely the way to go, unless you have some other way to discern one array from the other.
I agree with pludi. If you have more than one array, or even really just one array, use references as I showed in my other post. As far as @_ goes, he explained it well enough so I will leave it at that.