note
brycen
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:
<code>
#!/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);
</code>
<hr/>
<code>
$VAR1 = \{
'lat' => '37.7987145',
'tag' => {
'amenity' => {'v' => 'car_sharing' },
'operator' => {'v' => 'CityCarShare'},
'Bmenity' => {},
'Cmenity' => {},
},
'lon' => '-122.4436971',
'id' => '992609516'
};
</code>
800779
800779