punkish has asked for the wisdom of the Perl Monks concerning the following question:
# 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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: mashing two arrays
by jettero (Monsignor) on Jan 19, 2007 at 17:41 UTC | |
by punkish (Priest) on Jan 19, 2007 at 17:51 UTC | |
by ikegami (Patriarch) on Jan 19, 2007 at 18:06 UTC | |
Re: mashing two arrays
by ferreira (Chaplain) on Jan 19, 2007 at 18:05 UTC | |
Re: mashing two arrays
by marcpestana (Initiate) on Jan 19, 2007 at 18:10 UTC | |
Re: mashing two arrays
by thospel (Hermit) on Jan 20, 2007 at 22:17 UTC | |
Re: mashing two arrays
by Anonymous Monk on Jan 24, 2007 at 15:17 UTC |