Ack! I overlooked the unsorted elements in your data. By way of apology, please accept this working, tested code. It is somewhat under-documented
and needs refactoring, but I am out of time tonight. For your two sample @sets, my code outputs:
[ 0, undef, 1, undef, undef, 2, 3, 4, 5, 6 ],
[ 0, 1, 2, 3, 4, 5, 6, undef, 7, 8 ],
[ 0, undef, 1, 2, 3, 4, 5, undef, 6, 7 ],
and: [ 0, 1, 2, undef, undef, 3, 4 ],
[ 0, 1, undef, 2, undef, 3, 4 ],
[ 0, 1, undef, undef, 2, 3, 4 ],
.
The code works by transforming all the lists into AoAs, with each element holding [$original_item, $original_index].
It merges the first two lists, via Algorithm::Diff (++belg4mit) to form elements [$original_item, $index_from_list1, $index_from_list2]. List 3 is then merged in, etc.
I *think* it will work fine for *any* number of lists.
|