Printing Perl Hash Keys

前端 未结 3 1204
难免孤独
难免孤独 2021-02-07 11:37

I am trying to print out my Hash Keys in Perl, one per line. How would I go about doing this?

3条回答
  •  隐瞒了意图╮
    2021-02-07 12:13

    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;
    

提交回复
热议问题