beginnerinperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Can someone please help me with the following problem statement. There are 2 csv files. I want to compare both the files and print the difference to a text output file.

E.g. ---- File1.csv has the below content ------------------------------- 10, Apple, Juice 50, Eat, Something Need, Some, Help File2.csv --------- 10, Apple, Juice 50, Eat, Something How, To, Do I want the output file like this. Output.txt ----------- Line 3 is not matching. Line in File1: Need, Some, Help Line in File2: How, To, Do

As I am completely new to Perl language, can someone please help me with the code.

Thanks a ton !!

  • Comment on I want to compare 2 CSV files and print the difference in a text file
  • Download Code

Replies are listed 'Best First'.
Re: I want to compare 2 CSV files and print the difference in a text file
by Tux (Canon) on Feb 12, 2018 at 11:52 UTC

    Or show us what you tried so far, so we can comment on your code.


    Enjoy, Have FUN! H.Merijn
      You don't have to install Text::CSV to read a whole line from a file, which is all that is required.
        1. I never referred to Text::CSV, but to Text::CSV_XS. Don't change the context.
        2. Both examples posted had three lines (which with my basic math is more than one).
        3. CSV should never be read as-is. It will work on the first example, but will fail when embedded newlines, quotation and escapes come into play.
        4. I offered the csvdiff tool, which depends on Text::CSV_XS.
        5. The op asked for processing (diff), not just reading (parsing) a single line.

        Enjoy, Have FUN! H.Merijn
Re: I want to compare 2 CSV files and print the difference in a text file
by haukex (Archbishop) on Feb 12, 2018 at 12:37 UTC

    Crossposted to StackOverflow. Crossposting is ok, but it is polite to inform others of the cross-posting so that efforts are not duplicated.