in reply to Grepping arrays, any better way to do this?

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.

  • Comment on Re: Grepping arrays, any better way to do this?