kpiti has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to merge two arrayrefs into one containing all the fields but not repeating them. For example:
my $arr1 = [[qw/name pos loc age/], [qw/ike boss 12 44/], [qw/mat slave 22 21/]]; my $arr2 = [[qw/car dog age/], [qw/a1 grr 3/]]; #...magic goes here and we want: my $arrMighty = [[name, pos, loc, age, car, dog], [ike, boss, 12, 44, "", ""], [mat, slave, 22, 21, "", ""], ["", "", "", 3, a1, grr]];
I don't need to have it in any order as long as the values in the original arrays match their new position (or empty string). Oh yes, the first arefs ($arr1->[0] and $arr2->[0]) are like field names and they merge into one row, the others are data..
I've gone counting the fields and adding them and going trough the arrays over again, it works but it looks like a mess and I'm just wondering if there is some sexy way to do this..
Much obliged for any enlightenments..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Merging two array(refs)
by choroba (Cardinal) on Jan 21, 2013 at 00:12 UTC | |
|
Re: Merging two array(refs)
by kpiti (Novice) on Jan 21, 2013 at 00:26 UTC | |
by choroba (Cardinal) on Jan 21, 2013 at 01:17 UTC | |
by kpiti (Novice) on Jan 21, 2013 at 01:43 UTC | |
by choroba (Cardinal) on Jan 21, 2013 at 01:59 UTC | |
by kpiti (Novice) on Jan 21, 2013 at 07:44 UTC | |
|
Re: Merging two array(refs)
by LanX (Saint) on Jan 21, 2013 at 07:47 UTC |