As this is a beginners list are you going to explain... push my @c, [EMAIL PROTECTED] @a}]; push @{$c[0]}, (@{shift @b})[1];
$c[$_->[0]] = [ @{$_} ] while $_ = shift @a; push @{$c[$_->[0]]}, $_->[1] while $_ = shift @b; -----Original Message----- From: Jay Savage [mailto:[EMAIL PROTECTED] Sent: 24 April 2008 14:53 To: Vishal G; Perl List Subject: Re: Joining/Merging AoA On Tue, Apr 22, 2008 at 2:28 AM, Vishal G <[EMAIL PROTECTED]> wrote: > Hi Guys, > > I have a little complicated problem... > > I have two arrays > > @a = ( ['id', 'name', 'age'], > ['1', 'Fred', '24'], > ['2', 'Frank', '42'], > ); > > @b = ( ['id', 'sex'], > ['1', 'm' ], > ['2', 'm'], > ); > > I want to join these two AoA, based on id, so the resulting array > will look like this > > @c = ( ['id', 'name', 'age', 'sex'], > ['1', 'Fred', '24', 'm' ], > ['2', 'Frank', '42', 'm'], > ); > > Any Ideas? > It really depends on the data. Are you certain that both lists will be in the same order? Are you certain that all data will exist for each person? If so you can just loop though both lists. That's not very robust, though, because as soon as you get a value that is one list and not the other, everything gets out of sync. I'd probably do something like the following, which stores the is in the array index, as well as the first element: push my @c, [EMAIL PROTECTED] @a}]; push @{$c[0]}, (@{shift @b})[1]; $c[$_->[0]] = [ @{$_} ] while $_ = shift @a; push @{$c[$_->[0]]}, $_->[1] while $_ = shift @b; HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom! This e-mail is from the PA Group. For more information, see www.thepagroup.com. This e-mail may contain confidential information. Only the addressee is permitted to read, copy, distribute or otherwise use this email or any attachments. If you have received it in error, please contact the sender immediately. Any opinion expressed in this e-mail is personal to the sender and may not reflect the opinion of the PA Group. Any e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business practices. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/