Ing. Branislav Gerzo wrote:
Hi pals,

Hello,

How can I add values to hash, when key is the same ? Example:

my %ha = ( 'test1' => [
{ 'test1_a' => 'a',
'test1_b' => 'b',
},
{
'test1_a' => 'a',
'test1_b' => 'b',
}
] );


my %hb = ( 'test1' => [ {
'test1_c' => 'c'
},
{
'test1_d' => 'd'
}
]
);

To add values to the key 'test1':

push @{ $ha{ test1 } }, @{ $hb{ test1 } };


%ha is initial and will _always_ have all the keys, which has %hb. Now
I want this structure as result:

%result = ( 'test1' => [
{ 'test1_a' => 'a',
'test1_b' => 'b'
},
{
'test1_a' => 'a',
'test1_b' => 'b'
},
{
'test1_c' => 'c'
},
{
'test1_d' => 'd'
}
] );


order in hash doesn't matter. Anyone ?

my %result = ( test1 => [ @{ $ha{ test1 } }, @{ $hb{ test1 } } ] );



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to