Printing an array within double quotes

后端 未结 5 1741
栀梦
栀梦 2020-12-18 08:17
my @a = (1,2,3,4,5);

print @a;      #output: 12345

print \"\\n\";

print \"@a\";    #output: 1 2 3 4 5

Printing an array by putting its name with

5条回答
  •  醉酒成梦
    2020-12-18 08:57

    When an array is interpolated in a string, the assumption is you may want to be able to visually distinguish elements; when you print a list, the assumption is you just want that data output contiguously. Both are configurable; $, (default '') is inserted between elements of a list being printed, while $" (default ' ') is inserted between elements of an array interpolated into a string.

提交回复
热议问题