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
When Perl sees an array in an interpolated string, it rewrites it using join:
print "@array";
becomes
print join($" => @array);
by default, the value of $" is equal to a single space.
You can configure this behavior by localizing a change to $"
print "@array"; # '1 2 3 4 5'
{
local $" = ''; # "
print "@array"; # '12345'
}
print "@array"; # '1 2 3 4 5'
You can see how Perl rewrites your interpolated strings using the -q option of the core B::Deparse module:
$ perl -MO=Deparse,-q -e 'print "@array"'
print join($", @array);
-e syntax OK