开发者

How can I print list elements separated by line feeds in Perl?

开发者 https://www.devze.com 2022-12-13 07:17 出处:网络
What is t开发者_如何学Che easiest way to print all a list\'s elements separated by line feeds in Perl?print \"$_\\n\" for @list;

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消