The $data array is updated. Print any part you want.
...# As before
my @extras = grep {$_->{status} eq 'Extra'} @$data;
my @mains = grep {$_->{status} eq 'Main' } @$data;
MAIN:
foreach my $main (@mains) {
EXTRA:
foreach my $extra (@extras) {
next EXTRA if $main->{ID} ne $extra->{ID};
@{$main}{qw/new_name new_ad1 new_city new_z_code/}
= @{$extra}{qw/name Ad1 City zCode/};
}
print Dumper($main);
}
OUTPUT:
$VAR1 = {
'state' => 'TO',
'new_z_code' => '0007',
'zCode' => '0002',
'status' => 'Main',
'ID' => '2222',
'name' => 'John D',
'City' => 'NY',
'new_city' => 'BO',
'new_ad1' => '100 main St.',
'Ad1' => '20 North Central St.',
'new_name' => 'Tony Star'
};
$VAR1 = {
'zCode' => '2334',
'status' => 'Main',
'ID' => '1111',
'state' => 'CA',
'new_z_code' => '9857',
'Ad1' => '12th Street',
'new_name' => 'Marie Doe',
'name' => 'Charles D',
'City' => 'NM',
'new_city' => 'MA',
'new_ad1' => '44 Dell St'
};
$VAR1 = {
'City' => 'AA',
'name' => 'AKAKAK',
'state' => 'PP',
'ID' => '8888',
'Ad1' => '1AAAA',
'zCode' => 'TTTT',
'status' => 'Main'
};
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.