Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: using ref to hash of hash effectively

by GrandFather (Saint)
on Dec 27, 2020 at 02:03 UTC ( #11125776=note: print w/replies, xml ) Need Help??


in reply to using ref to hash of hash effectively

You can dereference two ways:

use warnings; use strict; my $weapons_ref = { dagger => { cost => 8, damage => 4, armor => 0 }, shortsword => { cost => 10, damage => 5, armor => 0 }, warhammer => { cost => 25, damage => 6, armor => 0 }, longsword => { cost => 40, damage => 7, armor => 0 }, greataxe => { cost => 74, damage => 8, armor => 0 }, }; print "$weapons_ref->{dagger}{cost}, ${$weapons_ref}{dagger}{damage}";

Using -> or {$reference} is somewhat a matter of personal preference in simple cases, but the {} form can be easier to read when things get complicated. See perlref.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11125776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-06-17 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (84 votes). Check out past polls.

    Notices?