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;

In reply to Re^2: Question on file compare by sureshsmr
in thread Question on file compare by sureshsmr

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.