http://qs1969.pair.com?node_id=906704


in reply to Best Multidimensional Hash Practices?

Here's a complete example of using the Perl vivification module, which you can find on CPAN. Perl's implicit instantiation of hash elements can readily be controlled with fine granularity:
#!/usr/bin/perl -w use Data::Dumper; my $hash = { 'id' => '992609516', 'lat' => '37.7987145', 'lon' => '-122.4436971', 'tag' => { 'operator' => { 'v' => 'CityCarShare' }, 'amenity' => { 'v' => 'car_sharing' }, }, }; print "Id: $hash->{id}\n"; print "Amenity: $hash->{tag}{amenity}{v}\n"; print "Bmenity: $hash->{tag}{Bmenity}{v}\n"; print "Cmenity: $hash->{tag}{Cmenity}{v}\n" if exists($hash->{tag}{Cmenity}{v}); no autovivification 'exists'; print "Dmenity: $hash->{tag}{Dmenity}{v}\n" if exists($hash->{tag}{Dmenity}{v}); no autovivification; print "Emenity: $hash->{tag}{Emenity}{v}\n"; print Data::Dumper::Dumper(\$hash);

$VAR1 = \{ 'lat' => '37.7987145', 'tag' => { 'amenity' => {'v' => 'car_sharing' }, 'operator' => {'v' => 'CityCarShare'}, 'Bmenity' => {}, 'Cmenity' => {}, }, 'lon' => '-122.4436971', 'id' => '992609516' };