CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Search content of one file with the content of a second file: Edit Log



perlfree
Novice

Mar 25, 2011, 2:44 PM


Views: 6677
Search content of one file with the content of a second file

Hi,

I have two files:

File1 (tab-delimited and two columns):
Ex_efxb 0.0023
MSeef 2.3000
F_ecjc 0.3338
MWEEI -0.111
DDAIij 17.777

File2:
MSeef 2.3000
F_ecjc 0.3338

I want to search the content of File one using the content of File 2 and then display the output as follows:

Date of search:
The following matches were found in File 1:

MSeef 2.3000
F_ecjc 0.3338


Here's is my perl script which did not work for the above tasks

Code
#!C:\bin\perl.exe  


my $REPORT_FILE = 'outFile.txt';

$F1 = 'File1.txt';
open(RF,"<$F1") || die "can't open $F1 $!";


$F2 = 'File2.txt';
open(RXNs,"<$F2") || die "can't open $F2 $!";
close F1;
close F2;


my $line = <RF>;
@f1 = split /\t/, $line;

my $line = <RXN>;
@f2 = $line;



open(DATA,"+>OutFile.txt") or die "Can't open data";

foreach $a (@f1){
$flag = 0;
foreach $b (@f2){
if ($a eq $b){
print DATA $line{1}."\t".$line{2}."\n" ;
$flag = 1;
last;
}
if ($flag==0){
print DATA "";
}
}

}
close DATA;


help would be appreciated to make the script work.
Thanks


(This post was edited by perlfree on Mar 25, 2011, 3:05 PM)


Edit Log:
Post edited by perlfree (Novice) on Mar 25, 2011, 2:49 PM
Post edited by perlfree (Novice) on Mar 25, 2011, 2:50 PM
Post edited by perlfree (Novice) on Mar 25, 2011, 2:58 PM
Post edited by perlfree (Novice) on Mar 25, 2011, 3:03 PM
Post edited by perlfree (Novice) on Mar 25, 2011, 3:05 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives