Solved

merging a hash with array of hashes

Posted on 2009-05-06
2
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 84

Accepted Solution

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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

615 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