Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > RE: Joining/Mer...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 10986 of 11065
Post > Topic >>

RE: Joining/Merging AoA

by andrew.curry@[EMAIL PROTECTED] (Andrew Curry) Apr 24, 2008 at 03:48 PM

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.




 1 Posts in Topic:
RE: Joining/Merging AoA
andrew.curry@[EMAIL PROTE  2008-04-24 15:48:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 23:26:37 CDT 2008.