首页 文章

打印Perl哈希密钥

提问于
浏览
11

我试图在Perl中打印出我的Hash密钥,每行一个 . 我该怎么做呢?

3 回答

  • 24

    这样做适合你吗?

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

    精简版:

    $, = "\n";
    print keys %hash;
    

    或者在更大的脚本中:

    {
        local $, = "\n";
        print keys %hash;
    }
    

    把它放在变量中,根据你的评论在消息框中打印:

    my $var = join "\n", keys %hash;
    
  • 3

    我们可以通过使用map函数来完成 .

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

    map函数处理其对散列中每个键的语句 .

相关问题