The above code prints "Pete Hollister". Here's the same thing with a hash of arrays:my %people = ( 7 => { name => 'Bob Jones', address => '555 Anywhere Street', city => 'Allentown', state => 'Pennsylvania' }, 3 => { name => 'Pete Hollister', address => '222 Northview Drive', city => 'Shoreham', state => 'unknown' } ); my $idnumber = 3; print $people{ $idnumber }{ name };
Or, to be complete obnoxious (and I don't recommend this), we could go with an array of pseudo-hashes which would allow you to use this as a hash of hashes or a hash of arrays as you like:my %people = ( 7 => [ 'Bob Jones', '555 Anywhere Street', 'Allentown', + 'Pennsylvania' ], 3 => [ 'Pete Hollister', '222 Northview Drive', 'Shoreh +am', 'unknown' ] ); my $idnumber = 3; print $people{ $idnumber }[0];
The above resulted from my being a bit bored at work and having some free time. I was just playing around and I strongly advise against this approach. Aside from the difficulties with maintenance, merlyn mentioned that pseudo-hashes are probably not going to be in Perl 6.my $phashref = { name => 1, address => 2, city => 3, state => 4 }; my %people = ( 7 =>[$phashref, 'Bob Jones', '555 Anywhere Street', 'Al +lentown', 'Pennsylvania' ], 3 =>[$phashref, 'Pete Hollister', '222 Northview Drive' +, 'Shoreham', 'unknown' ] ); my $idnumber = 3; print $people{ $idnumber }->{ name } . "\n"; print $people{ $idnumber }->[1];
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re: Complex Data Structures?
by Ovid
in thread Complex Data Structures?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |