# I have the following two arrays @foo = ( # date_time -----# #foo# ["20031001 000000", 1.4], ["20031001 001500", 1.5], ["20031001 003000", 1.6], ["20031001 004500", 1.5], ["20031001 010000", 1.4], ); @bar = ( # date_time -----# #bar# ["20031001 000000", 0.001], ["20031001 000005", 0.004], ["20031001 000015", 0.005], ["20031001 001000", 0.008], ["20031001 001005", 0.007], ["20031001 001500", 0.007], ["20031001 001515", 0.007], ); # and I want the following array # @baz is a mashup of the above two # @baz is sorted on the date_time stamps (the first col), and # 'undef' is used for any missing value in corresponding arrays @baz = ( # date_time -----# #foo#, #bar# ["20031001 000000", 1.4, 0.001], ["20031001 000005", undef, 0.004], ["20031001 000015", undef, 0.005], ["20031001 001000", undef, 0.008], ["20031001 001005", undef, 0.007], ["20031001 001500", 1.5, 0.007], ["20031001 001515", undef, 0.007], ["20031001 003000", 1.6, undef], ["20031001 004500", 1.5, undef], ["20031001 010000", 1.4, undef], );
In real world, both foo and bar are rather large (a few thousand elements each), and either one could be bigger than the other.
I have tried to create a hash with date_time as keys to avoid duplicate time stamps, checking for existence of keys, and suitably mashing them together, then sorting the hash on its keys to write out an array. But my code is messy and bad, and slow, and I am fatigued, and bad, and slow now. Any pointers would be appreciated.
In reply to mashing two arrays by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |