An even better question is: why doesn't it print something like an array {0x1232ef}. Printing should print the output of a string, @anot a scalar.
Hell, even better: this is a scalar context, so why not print 5, which is the number of elements in the array. Here's how to do it:
print scalar @a;
.
print , , , , , .
:
@a = qw(a b c d e);
print "@a";
print "\n";
print @a;
print "\n";
print @a . "\n";
print scalar @a;
, print @a abcde, \n , @a .
Perldoc ( perldoc -f print. Perl perldoc)
* print LIST
* print
Prints a string or a list of strings. Returns true if successful[...]
! , .
$, ( ) LIST. $\ ( ) . print LIST, LIST , , .
:
@a = qw(a b c d e);
$, = "--";
print "@a";
print "\n";
print @a;
print "\n";
print @a . "\n";
print scalar @a;
... $, , @a . , $, perldoc, why is everyone prattling about $"`?
perldoc perlvar
* $LIST_SEPARATOR
* $"
When an array or an array slice is interpolated into a double-quoted string or a
similar context such as /.../ , its elements are separated by this value. Default
is a space. For example, this:
print "The array is: @array\n";
is equivalent to this:
print "The array is: " . join($", @array) . "\n";
Mnemonic: works in double-quoted context.
, !
$" - , $, null. , !
...
@a = qw(a b c d e);
$, = "--";
$" = "++";
print "@a";
print "\n";
print @a;
print "\n";
print @a . "\n";
print scalar @a;