|Perl Monk, Perl Meditation|
Re^5: Dereferencing arraysby BrowserUk (Pope)
|on Mar 19, 2014 at 21:11 UTC||Need Help??|
Because you cannot pass arrays to subroutines; you can only pass a (single) list.
This reality stems from this:
There is nothing to delimit the two different lists on the right hand side; so everything -- the numbers and the letters -- gets assigned to @a; nothing to @b;
Similarly, when you do this:
All the items from both arrays and the single scalar get concatenated into a single list, which inside the function you address as the array @_.
When you assign @_ to two arrays and a scalar inside your function:
The information about which elements of @_ came from which argument has been lost; so everything gets assigned to @groupA and nothing to the other two variables.
Hence if you want to pass multiple arrays (or hashes; or combination thereof) to a function, you have to pass references to them and dereference internally.
It might sound like a limitation, but once you start using your function to sort arrays of any size, you'll be glad of the efficiency that results.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.