Hi all, I am a beginner to perl, trying to do automate a test case which is comparison of all the records in one csv file to the recors in the second csv file. wht exactly i am trying to do is : take one record from first csv file and compare with all records in the other csv file if found a match, say its matched other mismatch.

I have written with my initial knowledge, couldnt find where iam going wrong.

for my $arg (@ARGV) { #$script=$ARGV[0]; #$stanza=$ARGV[1]; $metricsfile=$ARGV[0]; $resultfile=$ARGV[1]; } print "MetricsFilename:$metricsfile\n"; ### Assigning the argument file to in_file #### $in_file = $metricsfile; ### Opening the input file to read #### open (IN, "<$in_file") or die "Can't open $in_file: $!"; ### A while condition to read all the lines in a file and place in an +array#### #my $linenum=1; while(@linesFromMetrics=<IN>){ # opening while loop #print "Reading metrics file \n"; #print $linenum++; # closing while loop foreach $Metricsline(@linesFromMetrics){ ####------------------------------------------##### ### READING THE RESULTS CSV FILE ##### ####----------------------------------------#### print "ResultFilename:$resultfile\n"; ### Assigning the argument file to in_file #### $input_file = $resultfile; ### Opening the input file to read #### open (INPUT, "<$input_file") or die "Can't open $input_file: $!"; ### A while condition to read all the lines in a file and place in an + array#### while(@linesFromresultfile=<INPUT>){ # opening while loop my $var=false; foreach $Resultline(@linesFromresultfile){ if($Metricsline eq $Resultline){ print "The lines from metrics file :$Metricsline \n"; print "The lines from results file :$Resultline \n"; print "The line matches \n"; $var=true; } } # result file for each loop if($var=false) { print "mismatch"; } } # while results file close INPUT; } # metrics file for each loop } # while metrics file close IN;
can any guide me, where i am going wrong or is there any other way of doing

In reply to compare records in two csv files by boddeti

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.