in reply to Using 'keys' on a list
PS: I did find that say for keys %{{f}}; did indeed work.use strict; use warnings; use Data::Dumper; use v5.10; sub f {a=>1,b=>2} my %result = f(); #converts a a hash passed as an arry #back into a hash print Dumper \%result; print "to print just the keys of the hash:\n"; say "$_" for keys %result; # this is much faster, execution wise... # passes back a referecne to a hash that has # been already been created. sub x { my %result; $result{a}=1; #more likely way to set the results $result{b}=2; return \%result; } my $hash_ref = x(); print "to print the keys of this hash\n"; print "$_\n" for keys (%$hash_ref); print Dumper $hash_ref; __END__ $VAR1 = { 'b' => 2, 'a' => 1 }; to print just the keys of the hash: b a to print the keys of this hash a b $VAR1 = { 'a' => 1, 'b' => 2 };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using 'keys' on a list
by Anonymous Monk on Jun 30, 2021 at 12:11 UTC | |
by Marshall (Canon) on Jul 02, 2021 at 19:27 UTC | |
by Anonymous Monk on Jul 02, 2021 at 21:08 UTC | |
by Marshall (Canon) on Jul 02, 2021 at 22:05 UTC | |
by Anonymous Monk on Jul 02, 2021 at 22:26 UTC | |
|