Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: using ref to hash of hash effectively

by GrandFather (Saint)
on Dec 27, 2020 at 02:03 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-25 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found