Solved

merging a hash with array of hashes

Posted on 2009-05-06
2
157 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl, group, sort, count question 6 117
pattern matching in perl 2 101
Perl modules on linux ec2 3 96
Matching a random pattern with one common character 2 45
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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now