in reply to Trying to learn about References

Here is an easy one - pass two (or more) arrays (or hashes) to a subroutine:
use strict; my @a = (0..4); my @b = ('a'..'e'); &foo(@a,@b); &bar(\@a,\@b); sub foo { my (@a,@b) = @_; print "a: ", join(',',@a), "\n"; print "b: ", join(',',@b), "\n"; } sub bar { my ($a,$b) = @_; print "a: ", join(',',@$a), "\n"; print "b: ", join(',',@$b), "\n"; }
Subroutine foo() tries to pass two arrays, and as a result they are 'squashed' into one array. Subroutine bar() passes the two arrays by reference, and because it 'asks' for references in this line:
my ($a,$b) = @_;
the arrays are not squashed. Maybe it would be clearer if you understand that @_ is an array itself, from perldata (with a paraphrase by me):
You can actually put an array or hash anywhere in the list [subroutine arguments which are passed to @_], but the first one in the list will soak up all the values, and anything after it will become undefined.
Hence, in subroutine foo(), @a soaks up all of the elements that were meant for @b.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)