On Jan 7, 2013, at 5:33 PM, Neo Anderson wrote: > > I think there are two ways to declare an array: > my @a1 = (1, 2, 3);my @a2 = [1, 2, 3]; > What is the difference?
Both "my @a1;" and "my @a2" DECLARE an array. The difference here is what you are assigning to that array. "(1, 2, 3)" is a list, and you are assigning this list correctly to the array @a1. "[1, 2, 3]" is a a scalar value: a reference to an anonymous 3-element list, and you are incorrectly assigning that scalar value to the array @a2. That will give it a 1-element array. While it works, it is probably not what you want. More likely correct would be assigning the scalar reference value to a scalar variable: my $array_ref2 = [1, 2, 3]; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/