Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing Perl Hash Keys

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

like image 313
Dynamic Avatar asked Aug 15 '11 21:08

Dynamic


2 Answers

Does this do it for you?

print "$_\n" for keys %hash;
like image 62
piCookie Avatar answered Nov 11 '22 16:11

piCookie


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;
like image 36
TLP Avatar answered Nov 11 '22 16:11

TLP