Frankly, I do not see why using an %already_seen hash would be more complicated than a grep on the content of the smaller file. Actually, when I started to learn Perl about 10 years ago, it took me just a few days to be able to set up a solution with a hash for this type of problem, I learned to use the grep function only a number of months later.

Using a hash is also algorithmically much more intellectually satisfying. Granted, with about 1,000 records, it does not make much of a difference, and, to tell the truth, I am also sometimes lazy. I just found today a piece of code (not in Perl, in a programming language having no built-in sort function) that I wrote less than a year ago in which I developed a simple 5-line bubble sort, despite its known inefficiencies, just because I knew that my lists to be sorted would usually have an average 2 to 3 elements and never more than 6. Worse than that, in that same language that I mentioned, I am regularly using a goto instruction, because it is in my experience the best way to exit forward of a code block when looping on the records of a database (I am using it exclusively as an equivalent of the next instruction in a Perl loop). I am mentioning these things just to show that I am really not a CS purist or bigot, I also like to keep things simple when there is no point of making them complicated. In the case in point, however, the idea of visiting 1882 times 1042 records when you can do it only once (or twice, depending on what you count) at no cost in terms of code simplicity with a hash really goes against every tenet that I have learned over my past 30 years of programming experience.


In reply to Re: Matching 2 unordered arrays then printing the first array highlighting the matches? by Laurent_R
in thread Matching 2 unordered arrays then printing the first array highlighting the matches? by fraizerangus

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.