in reply to Merging two array(refs)
You could use nested slices of position informations of the column-heads
DB<158> @head1= @{$arr1->[0]} => ("name", "pos", "loc", "age") DB<159> @head2= @{$arr2->[0]} => ("car", "dog", "age") DB<161> %pos=();$p=0 DB<162> for ( @head1 , @head2 ) { $pos{$_}=$p++ unless exists $pos{$_} } DB<163> %pos => ("dog", 5, "loc", 2, "car", 4, "name", 0, "pos", 1, "age", 3)
DB<168> @n= ("") x $p #default => ("", "", "", "", "", "") DB<169> @n[ @pos{@head1} ] = @{ $arr1->[1] } => ("ike", "boss", 12, 44) DB<170> @n => ("ike", "boss", 12, 44, "", "") DB<171> @n= ("") x $p #default => ("", "", "", "", "", "") DB<172> @n[ @pos{@head2} ] = @{ $arr2->[1] } => ("a1", "grr", 3) DB<173> @n => ("", "", "", 3, "a1", "grr")
IMHO the sexiest approach so far! ;-)
Completing the code is now just a minor task...
HTH
Cheers Rolf
|
|---|