No such thing as a small change | |
PerlMonks |
How to filter few key value pairs from hash referenceby jaypal (Beadle) |
on Sep 15, 2014 at 16:55 UTC ( [id://1100620]=perlquestion: print w/replies, xml ) | Need Help?? |
jaypal has asked for the wisdom of the Perl Monks concerning the following question: Hello Perl Monks, I need some suggestions in filtering out few key value pairs from a hash reference. Here is a quick example that will probably demonstrate what I am trying to do (you will notice that in my final data structure the array of hashes has one key value pair less as it has been moved outside of array): Lets assume I have a following data structure:
From this array of hashes, I am interested in creating a hash of array of hashes which will have inner key of sex whose value will be array of hashes. My attempt to do this was as follows:
This was the output:
I am creating a copy of the hash reference and then manipulating the copy reference and then adding it to new data structure to protect my original data structure. Is there a better way to filter certain key value pairs from a hash reference without having to create a copy reference but protecting the original data structure. Since this is only for learning purposes, I am interested in looking at other options even if they come at the cost of readability. Looking forward to your wisdom.
Regards
Back to
Seekers of Perl Wisdom
|
|