Whether or not you like dragonchild's alternative, it is still true that you are making a full extra copy of the file data in memory, which you really don't need. You should leave out the "@lines" arrays, and replace the  for my $line (@lines) loops with  while (my $line = <$fh>) loops.

It might also save some memory and speed to use  $hash1->{$key} = undef because all you ever do with the hash1 and hash2 data is check for existence of keys.

It would be helpful to the potential user to be more clear about what exactly the "comparison" consists of, since there are many ways of comparing two csv files, and this script only addresses one way (print any record that contains a "key" value unique to either input file, i.e. not common to both files).

Some users might also like to know (by means of a description in pod, for example) what the limitations are for the code as written: there's no checking for repeated "keys" within a single file, and no checking whether a "common" key has same or different data in other fields in the two files.


In reply to Re: Compare 2 csv files using a key set of colums by graff
in thread Compare 2 csv files using a key set of colums by eric256

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.