Peter said:

> I'm on the first few chapters of "Learning Perl" and came up with a
> question. Given:
>
> -------------------------------------
>
> #!/usr/bin/perl
>
> @array = qw ( one two three );
> print @array . "\n";
> print @array;
>
> -------------------------------------
>
> Can you explain why the first print statement prints "3" (and a carriage
> return) while the second prints "onetwothree"?  My understanding is that
> the first print sees the array in scalar context while the second sees
> it in list context, but if so I don't understand why.  Can someone break
> it down what the concatenation operator is doing here?

Your understanding is correct.  Concatenation works on scalars, so the
array is evaluated in scalar context, returning 3, which is concatenated
with "\n" and then printed.

In the second line, print takes a list, so the array is evaluated in list
context.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to