开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜