On Tue, Oct 07, 2003 at 01:09:26AM +0200, Kevin Pfeiffer wrote: > I just noticed that: > > print join ", ", @list, "\n"; > > produces output such as: > > a, > a, b, c, > > whereas: > > print join(", ", @list), "\n"; > > produces: > > a > a, b, c > > (no trailing comma) -- strange... I think I remember reading somewhere > that without the parentheses 'join' doesn't really know exactly where > to stop. Sound right?
It's not *wrong*, but you make this sound more haphazard than it really is. The join() operator takes a scalar and a list -- so when you don't use parentheses, the expression is parsed like this. my @array = qw(a b c); print( join(',', @array, "\n") ); The comma, the elements of the array, and the newline will all be passed as arguments to join(). So join() puts a comma between "a" and "b", between "b" and "c", and between "c" and "\n". Then print() gets just one argument: the result of join(), which is the string "a,b,c,\n". If you add the parentheses yourself and put them here: my @array = qw(a b c); print( join(',', @array), "\n" ); # ----> ^ <---- Then the comma and the elements of @array -- but NOT the newline -- are passed as arguments to join(). In this case join() puts a comma between "a" and "b" and between "b" and "c". And this time print() gets two arguments: the result of join(), which is "a,b,c", and the newline. -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]