SPUG: Slice of HashOfHash
Juan Jose Natera
naterajj at gmail.com
Wed Nov 15 16:39:23 PST 2006
On the other hand, if you do need to keep a copy of the results:
my %matched = map { $_ => $HoH{$_} } grep { $HoH{$_}->{husband} eq
'fred' } keys %HoH;
On 11/15/06, Eric.D.Peterson at alltel.com <Eric.D.Peterson at alltel.com> wrote:
>
>
>
> Given a Hash of a Hash is it possible to make a slice (I presume this will
> be another hash) of a subset of the HoH based upon a value, not the key?
> For example:
>
> my %HoH = (
> flintstones =>
> {
> husband => "fred",
> pal => "barney",
> },
> jetsons =>
> {
> husband => "george",
> wife => "jane",
> "his boy" => "elroy", # Key quotes needed.
> },
> jones =>
> {
> husband => "fred",
> wife => "linda",
> },
> simpsons =>
> {
> husband => "homer",
> wife => "marge",
> kid => "bart",
> }
> );
>
>
> How can I make a new hash or loop through this HoH where husband = "fred"?
>
> I've been reading up on slices and printing hashes, but I can't seem to find
> an example or description on playing with HoH subsets. I've tried looping
> through the full HoH and adding those desired elements to a new HoH but that
> seems awkward and not quite right & cumbersome. So I thought I'd ask ya'll
> for some help.
>
>
> Cheers
> Eric
>
> ******************************************************************************************
> The information contained in this message, including attachments, may
> contain
> privileged or confidential information that is intended to be delivered only
> to the
> person identified above. If you are not the intended recipient, or the
> person
> responsible for delivering this message to the intended recipient, Alltel
> requests
> that you immediately notify the sender and asks that you do not read the
> message or its
> attachments, and that you delete them without copying or sending them to
> anyone else.
>
>
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays
> WEB PAGE: http://seattleperl.org/
>
>
More information about the spug-list
mailing list