开发者

Printing Perl Hash Keys

开发者 https://www.devze.com 2023-03-28 19:59 出处:网络
I 开发者_StackOverflow中文版am trying to print out my Hash Keys in Perl, one per line. How would I go about doing this?Does this do it for you?

I 开发者_StackOverflow中文版am trying to print out my Hash Keys in Perl, one per line. How would I go about doing this?


Does this do it for you?

print "$_\n" for keys %hash;


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;


We can done this by using map function.

map {print "$_\n"} keys %hash; 

map function process its statement for every keys in the hash.

0

精彩评论

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