Why array print different-2 value using ,(comma) and .(period sign)?
my @arr = qw(12 5 78 56 1 785);
my @new_arr = sort { $a <=> $b } @arr;
print @new_arr . "\n\n" ; #### print 6
print @new_arr , "\n\n" ; #### print value 开发者_如何学Cin short order
Hi, Could anyone tell me why it is printing different-2 value.
Thx, Vijay
The first one prints the concatenation of @new_arr
with the string "\n\n". That contatenation forces scalar context on @new_arr
, hence it evaluates as its number of elements, in your case 6.
The second one evaluates all arguments to print
in list context, hence @new_arr
evaluates to the list of all its elements.
精彩评论