Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Reference/Alias inner hash section

by broomduster (Priest)
on Sep 08, 2008 at 23:46 UTC ( [id://709921]=note: print w/replies, xml ) Need Help??


in reply to Reference/Alias inner hash section

You need:

use strict; use warnings; use Data::Dumper; my %a; $a{'WI'}{'GreenBay'}{'Color'} = 'Black'; foreach my $update ("WI,GreenBay,White") { my ($state,$city,$color) = split /,/, $update; my $h = $a{$state}{$city}; $h->{'Color'} = $color; }; print Dumper(\%a), "\n"; __DATA__ $VAR1 = { 'WI' => { 'GreenBay' => { 'Color' => 'White' } } };

Note that using strictures will catch your spelling error ($updtate) when you split (which is why your hash appears to be empty). Also note that $a{$state}{$city} is already a reference to your "inner hash" (i.e., a hash of hashes already uses a reference).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-24 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found