2) code was a bit overly complicated - a possible re-formulation is below.
3) A positive comment: the way that you opened all the files at the beginning is a good idea. no need to do a whole bunch of work, only to find out later that for example you can't open the output file..
Code untested:
#!/usr/bin/perl -w use strict; my $FILE1 = "D:/Data/WES/File1.txt"; # You can use "/" my $FILE2 = "D:/Data/WES/File2.txt"; # avoids this \\ stuff my $FILE3 = "D:/Data/WES/File3.txt"; open(F1,'<', $FILE1) or die "Can't open $FILE1\n"; open(F2,'<', $FILE2) or die "Can't open $FILE2\n"; open(F3,'>', $FILE3) or die "Can't open $FILE3\n"; #F3 header goes here my %File2Parts; # why call it F1parts? these numbers are # coming from file 2. names matter. while (my $PartNumber = <F2>) { chomp $PartNumber; next if $PartNumber =~ /^\s*$/; # skip blank lines # often a "unseen" trailing blank line # can cause troubles $File2Parts{$PartNumber} = 1; } close F2; while (my $uline = <F1>) { chomp; #you need this when splitting on other than white space my @ufields = split(/\|/, $uline); my ($PartNumber, $Std_Cost, $Last_Paid_Price, $Qty_In_Stock, $Moto_Preferred_Part, $Rev, $Agile_Description) = (@ufields)[0,1,2,3,7,9,10]; if ($File2Parts{$PartNumber}) { print F3 "$PartNumber|$Std_Cost|$Last_Paid_Price|$Qty_In_Stock +|$Moto_Preferred_Part|$Rev|$Agile_Description\n"; } }
In reply to Re: Question on file compare
by Marshall
in thread Question on file compare
by sureshsmr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |