我试图在Perl中打印出我的Hash密钥,每行一个 . 我该怎么做呢?
这样做适合你吗?
print "$_\n" for keys %hash;
精简版:
$, = "\n"; print keys %hash;
或者在更大的脚本中:
{ local $, = "\n"; print keys %hash; }
把它放在变量中,根据你的评论在消息框中打印:
my $var = join "\n", keys %hash;
我们可以通过使用map函数来完成 .
map {print "$_\n"} keys %hash;
map函数处理其对散列中每个键的语句 .
3 回答
这样做适合你吗?
精简版:
或者在更大的脚本中:
把它放在变量中,根据你的评论在消息框中打印:
我们可以通过使用map函数来完成 .
map函数处理其对散列中每个键的语句 .