And the result isuse strict; use warnings; my $hashref = { normal_enemies => { cloud_guy => { attacktype => 'thunder', power => 4, hp => 5, }, rain_man => { attacktype => 'water', power => 3, hp => 7, }, flame_kid => { attacktype => 'fire', power => 6, hp => 4, }, }, boss_enemies => { large_shark => { attacktype => 'water'. power => 9, hp => 13, special => 'none', }, wingding_monster => { attacktype => 'font'. power => 24, hp => 23, special => 'encrypt', }, green_dragon => { attacktype => 'fire'. power => 8, hp => 58, special => 'fire breath', }, }, items => { weapons => { sword_chucks => { power => 28, accuracy => 6, recommended_class => 'Crazy Fighter', }, cane => { power => 7, accuracy => 3, recommended_class => 'The Mage That Just Uses Magic. Y +ou know, if he ever needs to use this thing you\'re screwed anyway, r +ight?', }, katana => { power => 'over nine-thousand', accuracy => 8, recommended_class => 'Ninja Assassin', }, }, armor => { helm => { body_part => 'head', defense => 2.5, }, guantlets => { body_part => 'hands', defense => 1, }, necklace => { body_part => 'neck', defense => .1337, }, }, }, }; my %hash = %$hashref; print "Normal(Should fail with 'HASH(0xhex)' - $hashref\n"; print "Dereferenced - \n"; foreach (keys %hash) { print "$_ - $hash{$_}\n"; }
Now, what I want to do is take %hash deeper into the hashref. For example, how would I get a list of normal_enemies or the information from sword_chucks(this should come out as 'power - 28' instead of 'power - HASH(junk)') ? Thanks in advanced.Normal(Should fail with 'HASH(0xhex)' - HASH(0x99aae4) Dereferenced - normal_enemies - HASH(0x98a814) boss_enemies - HASH(0x99adc4) items - HASH(0x99ab24)
In reply to getting keys of multi-level hashrefs by mask_man
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |