On Mon, Jun 23, 2003 at 11:13:00PM -0500, Peter wrote: > I'm on the first few chapters of "Learning Perl" and came up with a > question. Given: > > ------------------------------------- > > @array = qw ( one two three ); > print @array . "\n"; > print @array; > > ------------------------------------- > > Why does the first print statement print "3" (and a carriage return) > while the second prints "onetwothree"? I'm guessing 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?
You nailed it; it's a context problem. C<print> evaluates its arguments in list context, but C<.> evaluates ITS arguments in scalar context, and it gets evaluated before the print. This would be more clear if we pretended that C<.> was a prefix function like C<print>, instead of a circumfix. Then the lines above would look like this: print( .(@array, "\n") ); ^ ^ | |------- scalar context starts here | list context starts here In contrast, when you do this: print( @array ); ...there is no context at work except that enforced by the C<print>. Did that help? --Dks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]