Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

merging a hash with array of hashes

Posted on 2009-05-06
2
Medium Priority
?
166 Views
Last Modified: 2012-05-06
Can somebody help me append the keys in a hash that are not in an array of hashes? just the keys that are not in that AoH, the rest should remain as it was originally in the AoH. Thanks!

my %Line = ('LIST'=>'2','PAGES'=>'77','EDITION'=>'new');
my @AoH = ({'LIST'=>'2','PAGES'=>'100'},
                      {'LIST'=>'10','EDITION'=>'new'},
                      {'PAGES'=>'30','EDITION'=>'old'},
                      {'LIST'=>'2','PAGES'=>'300'});

desired outcome:

my %Line = ('LIST'=>'2','PAGES'=>'77','EDITION'=>'new');
 my @AoH = ({'LIST'=>'2','PAGES'=>'100','EDITION'=>'new'},
{'LIST'=>'10','PAGES'=>'77','EDITION'=>'new'},
{'LIST'=>'2','PAGES'=>'30','EDITION'=>'old'},
{'LIST'=>'2','PAGES'=>'300','EDITION'=>'old','EDITION'=>'new'});
0
Comment
Question by:cucugirl
  • 2
2 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 500 total points
ID: 24318412
%$_=(%Line,%$_) for  @AoH;
0
 
LVL 85

Expert Comment

by:ozo
ID: 24318462
#if there are many keys in @AoH, and all the values are true, it may be more efficient to do
for my $h ( @Aoh ){ $h->{$_} ||= $Line{$_} for keys %Line }
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question