I used to have nightmares with hashes starting out.
A couple of things that I started doing that I think helped me out..
If I am going to have a complex structure, I start out with an anon hash, and I stick to anonymous arrays and hashes.
#!/usr/bin/perl -w use strict; my $house = { name => 'old bertha home', guests => [ 'greg', 'thomax', 'zeimart', 'bubba' ], structure => { rooms => [ 'foyer', 'bathroom', 'front lawn', 'kitchen'], address => '121 super road, ny, ny 12866', }, }; for ( @{$house->{guests}} ) { print "$_ is in house: ".$house->{name}; print " in the ". $house->{structure}->{rooms}->[ int(rand(3))] ."\ +n"; }
So, now you don't have to worry when passing references to function calls, if you pass it function(\%poppa); or function(\@poppa); etc.. it's always function($poppa); ... less typing too.
Also, name your hashes singular, always. name your arrays plural, always.
There's also the reasoning behind not doing this:
$$house{structure}{address}
instead of this
$house->{structure}->{address}
And thank goodness that someone wrote a book about that kind of thing so I can go to sleep now.. my eyes.. ouch...
Seriously, try it out. Use anonymous scalars, it may be your salvation.
In reply to Re: Hashes of Arrays of Hashes (sometimes of Arrays)
by leocharre
in thread Hashes of Arrays of Hashes (sometimes of Arrays)
by Bro. Doug
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |