From: <sono...@fannullone.us> I ran across something interesting today. I'm getting different results for an array depending on how it's used, as follows:
say @fieldnames; prints UIDGroupNamelastmodcategoryhtmlhidettsortorder ----- say "fieldnames = " . @fieldnames; prints fieldnames = 7 ----- say "fieldnames = @fieldnames"; prints fieldnames = UID GroupName lastmod categoryhtml hide tt sortorder ----- Why does @fieldnames give a different result depending on how it's used within a say statement? Thanks, When you quote an array, the elements of that array will be separated by the content of variable $". Try putting this line before print(): $" = ''; When you just print the array without quoting it, the elements of the array are separated by the content of the variable $, Try putting the following line before print(): $, = ' '; You will see that now the elements of the array printed between quotes are not separated by space, while the elements of the array printed without quotes are separated by spaces. Of course, you can use anything for $, and $" variables, not only spaces. When you access an array in scalar context, you get the number of elements of that array. It is just like saying: $nr_of_elements = scalar @array; When you do: print @array; you access @array in list context, because the function print() expects a list. When you do: print "something" . @array; you access @array in scalar context, because the operator "." expects a scalar... HTH. Octavian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/