in reply to A better way for walking through HoHoH ?
Recursion to the rescue! :)
Mike
In reality, you'd probably pass in another sub reference which would be the action to invoke on the final values.sub handleRefs { my ($target, $keys_ar) = @_; if (ref $target eq "HASH") { foreach my $key(keys %$target) { handleHashOrElement($target->{$key},[@$keys_ar,$key]); } return; } if (ref $target eq "ARRAY") { print "ARRAY at @$keys_ar is [ @$target ]\n"; return; } print "Value at @$keys_ar is $target\n"; } handleRefs(\%rez, []);
Mike
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: A better way for walking through HoHoH ?
by ZlR (Chaplain) on Mar 24, 2010 at 13:42 UTC |
In Section
Seekers of Perl Wisdom