Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Best Multidimensional Hash Practices?

by brycen (Monk)
on May 25, 2011 at 20:38 UTC ( [id://906704]=note: print w/replies, xml ) Need Help??


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' };

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-26 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found