On Thu, May 29, 2014 at 3:20 PM, James Kerwin <jkerwin2...@gmail.com> wrote:
> Explain the difference between: > > ($test)=(@test); > > And > > $test=@test; > Parens on the left make it a "list" context, parens on the right make it a list. Bare scalar on the left make it "scalar context, bare array assigned in a scalar context return a scalar - that is, the number of elements. So, in the first, @test gets unrolled to a list of elements and assigned in list context, the first element gets assigned to the first list element in the LHS list, i.e. $test - as if $test = $test[0]; Note, in this case, the parens are optional on the RHS, as the same thing would happen in ($test) = @test; you can add to that LHS list my ($test1, $test2, $test3, @test4) = @test; and elements 0, 1, 2 go into the scalars and the rest is "slurped" into @test4. If there not enough elements, they get "undef". An array in scalar context returns it's element count, so you can do: if ( @test == 4 ) { print "There's 4 things in \@test!\n"; } -- a Andy Bach, afb...@gmail.com 608 658-1890 cell 608 261-5738 wk