Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-18 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found