I am trying to print out my Hash Keys in Perl, one per line. How would I go about doing this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Does this do it for you?
print "$_\n" for keys %hash;
回答2:
Short version:
$, = "\n";
print keys %hash;
Or inside a larger script:
{
local $, = "\n";
print keys %hash;
}
To put it in a variable, for printing in a message box in accordance to your comments:
my $var = join "\n", keys %hash;
回答3:
We can done this by using map function.
map {print "$_\n"} keys %hash;
map function process its statement for every keys in the hash.