Long list of remarks follows...
for my $arg (@ARGV) { #$script=$ARGV[0]; #$stanza=$ARGV[1]; $metricsfile=$ARGV[0]; $resultfile=$ARGV[1]; }
The for loop does nothing, remove it!
use strict; # always! use warnings; # always!
### Assigning the argument file to in_file #### $in_file = $metricsfile;
No need for cmts that do not improve readability, and even degrade it. Well written code should be self explanatory.
Why assigning to yet another scalar and not using $metricsfile directly?
open (IN, "<$in_file") or die "Can't open $in_file: $!";
For the n-th time, n being a huge integer: you'd better use the 3-args form of open and lexical filehandles.
### 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
NO! you either want
my @lines=<IN>; # or while (my $line=<IN>) { # ...
#print "Reading metrics file \n"; #print $linenum++;
You may be interested in $. - read more about in perldoc perlvar.
### Assigning the argument file to in_file #### $input_file = $resultfile;
Your comment is not consistent with your code in two ways: missing sigil and wrong variable name. One more reason not to have useless comments: if you change, say, a variable name, then you'll have to change the comment as well.
Well, that's kinda too much. I'll suggest you another way round - this assumes your files are reasonably sized:
#!/usr/bin/perl use strict; use warnings; die "Usage: $0 <file1> <file2>\n" unless @ARGV==2; my %orig=map {$_ => 1} do { open my $fh, '<', $ARGV[0] or die $!; <$fh>; }; open my $fh, '<', $ARGV[1] or die $!; $orig{$_} and print while <$fh>; __END__
This is intendedly minimal: expand and adapt to your needs!
In reply to Re: compare records in two csv files
by blazar
in thread compare records in two csv files
by boddeti
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |