# 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.

--

when small people start casting long shadows, it is time to go to bed

In reply to mashing two arrays by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.