|
|
| Pathologically Eclectic Rubbish Lister | |
| PerlMonks |
Pushing arrays into hashesby BiffBaker (Novice) |
| on Jun 22, 2007 at 17:42 UTC ( [id://622866]=perlquestion: print w/replies, xml ) | Need Help?? |
|
BiffBaker has asked for the wisdom of the Perl Monks concerning the following question: My system uses arrayrefs of arrayrefs containing what are in effect key-value pairs, e.g.:
It uses this data structure rather than a hash because it works better with the algorithms used in some places. I would like to access the data, however, as if it were a hashref, with similar syntax. Here is a construct I came up with:
The value 'fry' will be assigned to $party. The one caution is that if there is more than one element in $pairs with the key 'fish' (there should not be, but...), there may be problems. I believe the last element in the array with this key will be used. Does anyone have thoughts on this? Is there a better way to do what I am describing?
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||||||