in reply to getting keys of multi-level hashrefs
Call it using DigThroughHashref($hashref);sub DigThroughHashref { my $hr_data = shift; my @keystack = @_; foreach (keys %{$hr_data}) { if (ref ($hr_data->{$_}) eq "HASH") { print ("Digging through [$_]:\n"); push (@keystack, $_); DigThroughHashref($hr_data->{$_}, @keystack); pop (@keystack); } else { print (join ('->', @keystack) . "->$_ - $hr_data->{$_}\n") +; } } ## end foreach (keys %{$hr_data}) } ## end sub DigThroughHashref
Also, there is an error in your boss_enemies data. There are periods following the attacktype instead of comma's.
You can also useinstead of declaring an extra %hash-variable.foreach (keys %{$hashref}) { }
Edit: forgot ->$_ in the output
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: getting keys of multi-level hashrefs
by cdarke (Prior) on Jul 07, 2010 at 10:13 UTC | |
by Neighbour (Friar) on Jul 07, 2010 at 11:24 UTC | |
by mask_man (Initiate) on Jul 07, 2010 at 20:12 UTC | |
by Neighbour (Friar) on Jul 08, 2010 at 09:50 UTC |