in reply to Re: file merge
in thread file merge
handleArgs(); if($outfile) { open (STDOUT, ">$outfile") || die "Cannot redirect STDOUT\n"; } open(TEMP,$newFile) || die "Error opening $newFile\n"; open(FILE,$oldFile) || die "Error opening $oldFile\n"; while(<TEMP>) { push(@temp, $_); } while(<FILE>) { push(@file, $_); } %temp = sort(@temp); %file = sort(@file); OUTER: foreach $_ ($file) { next if /^\s*$/; #ignore empty lines next if /^\s*#/; #ignore comments chomp; # $_ = lc; while(%temp) { $x = shift %temp; next if ($x =~ /^\s*$/); next if ($x =~ /^\s*#/); chomp $x; @compX = split /,/, $x; @compY = split /,/, $_; $comparison = lc($compY[0..2]) cmp lc($compX[0..2]); print "$_ - $x = $comparison\n" if $DEBUG; if($comparison == 0) { print "Record match...checking pctChange \n"; $fpPctChange = abs(($compX[3] - $compY[3]) / $compX[3] * 1 +00); if ($fpPctChange > 1) { print " BUT pct. Change greater than one.for $_ +. Please Investigate.\n"; print "Here's what was Found $_ AND $x\n"; } next OUTER; } else { print "this record is not a match. $_ , $x\n" if $DEBUG; next OUTER; } } print " This oldFile record was not found in newFile file! $_\n"; } if($W) { foreach $temp (@temp) { print "Warning $temp not expected\n";} } sub handleArgs() { while(@ARGV) { print "In Handle args\n" if $DEBUG; #Enable warnings if($ARGV[0] =~ /-W/i) { $W = 1; shift(@ARGV); } elsif($ARGV[0] =~ /-t/i) { $oldFile = $ARGV[1]; splice(@ARGV, 0, 2); } elsif($ARGV[0] =~ /-d/i) { $newFile = $ARGV[1]; splice(@ARGV, 0, 2); } elsif($ARGV[0] =~ /-O/i) { $outfile = $ARGV[1]; splice(@ARGV, 0, 2); } else { print "Invalid Arg in FileCmp ", shift (@ARGV),"\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: file merge
by graff (Chancellor) on Apr 05, 2005 at 23:02 UTC | |
by nraymond (Initiate) on Apr 11, 2005 at 15:02 UTC |