Tan has asked for the wisdom of the Perl Monks concerning the following question:
Dear All,
Please find the script below which although doesnt have immediate errors..is not what I was hoping it would acheive!
#perl -w print("Importing two data files \n"); # Lets open up file A which reads data from names_ticker to FILE_A open(FILE_A, "< Names_Ticker.txt") or die "Couldn't open Names_Ticker for reading: $!\n"; @fileA=<FILE_A>; close(FILE_A); print "@fileA \n"; # Lets open up file B which reads data from names_offer to FILE_B open(FILE_B, "< Names_Offer.txt") or die "Couldn't open Names_Offer for reading: $!\n"; @fileB=<FILE_B>; close(FILE_B); print "@fileB \n"; #Print the lists generated with commas... sort the format out! #sub commify_series { # my $sepchar = grep(/,/ => @_) ? ";" : ","; # (@_ == 0) ? '' : # (@_ == 1) ? $_[0] : # (@_ == 2) ? join(" and ", @_) : # join("$sepchar ", @_[0..($#_-1)], "and $_[-1]"); # } # #foreach $aref(@fileB) { # print "This lists contains: " . commify_series(@aref) . ".\n" +; # #} print("Comparing company names between two files\n"); # Essentially we want to find elements that are in one array but not a +nother, # that is find elements in @fileA that arent in @fileB. # Solution? build hash keys of @fileB to use as a lookup table. Then c +heck each # element in @fileA to see if it is in @fileB %seen = () ; # lookup table to test memebership of @fileB @aonly = () ; # answer # build lookup table foreach $item (@fileB) { $seen{$item} = 1} # find only elements in @fileA and not in @fileB foreach $item (@fileA) { unless ($seen{$item}) { # its not in %seen, so add to @aonly push(@aonly, $item); } } print "@aonly \n"; print("Saving matched company records as new file\n");
Ideally, as suggested from previous email - I am merging two records @fileA and @fileB into a single new file which is given as @aonly.
Problems I face:Your advice will be appreciated.
regards
Edited by Chady -- cleaned up formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fuzzy Matching
by !1 (Hermit) on Dec 30, 2003 at 09:55 UTC | |
| |
|
Re: Fuzzy Matching
by Art_XIV (Hermit) on Dec 30, 2003 at 14:10 UTC |