in reply to Re: Question on file compare
in thread Question on file compare
Thanks a million to all for helpful suggestions. Dear Marshall, I made all changes as suggested. I am not getting any errors But looks like the "if ($File2Parts{$PartNumber})" is not working as expected. If I put the "print F3 ..." line outside the if condition it is writing File3. Any ideas? Here is my modified code:
#!/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 $uline; #you need this when splitting on other than white s +pace 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]; # print F3 "$PartNumber|$Std_Cost|$Last_Paid_Price|$Qty_In_Stock|$ +Moto_Preferred_Part|$Rev|$Agile_Description\n"; if ($File2Parts{$PartNumber}) { print F3 "$PartNumber|$Std_Cost|$Last_Paid_Price|$Qty_In_Stock +|$Moto_Preferred_Part|$Rev|$Agile_Description\n"; } } close F1; close F3;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Question on file compare
by Marshall (Canon) on Mar 14, 2012 at 00:25 UTC | |
by sureshsmr (Initiate) on Mar 14, 2012 at 15:58 UTC |