in reply to Re: Sne ding Information to Sub
in thread Sending Information to Sub
These fail because the first array encountered in the parameter list will gobble up all the remaining values.some(@alphabet, "Foo"); # BAD! some("Foo", @alphabet, @alpha2); # BAD!
So you can do some("Foo", @alphabet); and it will work because the only array in the list is the last parameter (same rule for hashes), but some would argue that it could be the beginning of a bad habit -- because later you have to be especially alert if you add another parameter for this sub.
The option is to pass a reference to the array.
Thus allowing you to pass as many arrays and hashes as you may need and mix them with scalars in any order.some("Foo", \@alphabet); sub some { my ($one, $alpha_aref) = @_; my $letter_b = $alpha_aref->[1]; }
|
|---|