Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Reference/Alias inner hash section

by mpettis (Beadle)
on Sep 09, 2008 at 00:21 UTC ( [id://709933]=note: print w/replies, xml ) Need Help??


in reply to Re: Reference/Alias inner hash section
in thread Reference/Alias inner hash section

Oh fer cryin' out loud -- thanks, both of you. Try to mock up a quick stripped-down version, and I shoot myself in the foot. Thanks again, Matt

Replies are listed 'Best First'.
Re^3: Reference/Alias inner hash section
by ikegami (Patriarch) on Sep 09, 2008 at 00:28 UTC

    The difference between

    # broomduster my $h = $a{$state}{$city}; $h->{'Color'} = $color;

    and

    # ikegami my $r = \( $a{$state}->{$city} ); ${ $r }->{Color} = $color;

    is that only the latter autovivifies if necessary. For example, here's what happens if

    $a{'WI'}{'GreenBay'}{'Color'} = 'Black';
    is commented out:
    # broomduster $VAR1 = { 'WI' => {} };
    # ikegami $VAR1 = { 'WI' => { 'GreenBay' => { 'Color' => 'White' } } };

    The following would also do:

    my $h = $a{$state}{$city} ||= {}; $h->{'Color'} = $color;
      Thanks ikegami,

      autovivification was an issue -- I started out using broomduster's method, but set the sub-hash to '{}' if the hash keys didn't exist. Your method is more compact.

      Thanks, Matt

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-28 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found