As this is a beginners list are you going to explain...
push my @[EMAIL PROTECTED]
[@[EMAIL PROTECTED]
@[EMAIL PROTECTED]
push @[EMAIL PROTECTED]
(@[EMAIL PROTECTED]
@[EMAIL PROTECTED]
)[1];
$c[$_->[0]] =3D [ @[EMAIL PROTECTED]
] while $_ =3D shift @[EMAIL PROTECTED]
push @[EMAIL PROTECTED]
>[0]]}, $_->[1] while $_ =3D shift @[EMAIL PROTECTED]
Message-----
From: Jay Savage [mailto:daggerquill@[EMAIL PROTECTED]
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 <v3gupta@[EMAIL PROTECTED]
> wrote:
> Hi Guys,
>
> I have a little complicated problem...
>
> I have two arrays
>
> @[EMAIL PROTECTED]
=3D ( ['id', 'name', 'age'],
> ['1', 'Fred', '24'],
> ['2', 'Frank', '42'],
> );
>
> @[EMAIL PROTECTED]
=3D ( ['id', 'sex'],
> ['1', 'm' ],
> ['2', 'm'],
> );
>
> I want to join these two AoA, based on id, so the resulting array=20
> will look like this
>
> @[EMAIL PROTECTED]
=3D ( ['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 @[EMAIL PROTECTED]
[@[EMAIL PROTECTED]
@[EMAIL PROTECTED]
push @[EMAIL PROTECTED]
(@[EMAIL PROTECTED]
@[EMAIL PROTECTED]
)[1];
$c[$_->[0]] =3D [ @[EMAIL PROTECTED]
] while $_ =3D shift @[EMAIL PROTECTED]
push @[EMAIL PROTECTED]
>[0]]}, $_->[1] while $_ =3D shift @[EMAIL PROTECTED]
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 =E2 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.


|