I have to check for the existence of each of the dates from the first array in the second array
Whenever I see a phrase like this, a red light goes on in my head, with the caption "use a hash!"

Your code isn't actually working, that grep looks very fishy, for one, so I can't produce equivalent working code using a hash, but the idea would be that you build a hash traversing one array, and that you use the existence of an item in this hash as a flag, when traversing the second array.

Lookup in a hash is much faster than grepping through an array, and the larger the list, the higher the gain.

You do need to make sure you do an exact lookup, not an approaximate one, for this to work.


In reply to Re: Grepping arrays, any better way to do this? by bart
in thread Grepping arrays, any better way to do this? by chanakya

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.