in reply to Re^2: Reference/Alias inner hash section
in thread Reference/Alias inner hash section
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
is commented out:$a{'WI'}{'GreenBay'}{'Color'} = 'Black';
# broomduster $VAR1 = { 'WI' => {} };
# ikegami $VAR1 = { 'WI' => { 'GreenBay' => { 'Color' => 'White' } } };
The following would also do:
my $h = $a{$state}{$city} ||= {}; $h->{'Color'} = $color;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Reference/Alias inner hash section
by mpettis (Beadle) on Sep 09, 2008 at 00:39 UTC |