First, you can shorten your code just a bit by removing the use of $_.
while (my $ptfkey = <F2>)
The regex where you read in file 2 has a couple of issues. First, it forces start and end of line matching (^ and $, respectively). Next, it only matches the pipe and the whitespace on either side of it, so it will only match lines with ' | \n'. Lastly, it deletes everything that it matches.
If you only need to identify information in the first column, you only need to do this:
while (<F2>) { $ptfkey = $_; # you can skip this using above suggestion $ptfpn = $ptfkey; # don't need this if just matching $ptfpn =~ m/^(\w+)/; # if only letters and numbers $ptfpn =~ m/^([\d\-\.]+)/; # if it's a float $F1hash{$1} = 1; }
Secondly, the line that checks for the value should be throwing you an error:
if ($PartNumber =~ $Flhash{$PartNumber}) {
(Or, there are some languages that treat '=~' as a negation, kind of like '!=', so it could just be a typo.)
All you need to do is check to see if the value exists in the hash we created above:
if (exists $F1hash{$PartNumber}) {
Hope this helps.
Edit: I also just realized you declared %F1hash twice -- you should add the following to your code:
#!c:\perl\bin\perl -w # note the addition of the -w use diagnostics; use strict;
In reply to Re: Question on file compare
by muppetjones
in thread Question on file compare
by sureshsmr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |