How can I print list elements separated by line feeds in Perl?
What is t开发者_如何学Che easiest way to print all a list's elements separated by line feeds in Perl?
print "$_\n" for @list;
In Perl 5.10:
say for @list;
Another way:
print join("\n", @list), "\n";
Or (5.10):
say join "\n", @list;
Or how about:
print map { "$_\n" } @list;
Why not abuse Perl's global variables instead
local $\ = "\n";
local $, = "\n";
print @array;
If you get excited for unnecessary variable interpolation feel free to use this version instead:
local $" = "\n";
print "@array\n";
print join "\n", @list;
精彩评论