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: Regular Expressions: Search and extraction help: Edit Log



perlfree
Novice

Mar 3, 2010, 3:56 PM


Views: 4432
Search and extraction help

Hi,

I need help to make a perl program work. The program accepts an input (reaction) and then search for the input in a file and then displays the reaction on the same line.

Input file - file.txt (A large file with no header and in the following format):
A1_HTTT24 : GLUC_ext = GLUC .
C2_GLH3 : GLUC + ATP = GLUC6P + ADP .
B3_PGAI1 : GLUC6P = FRUC6P .

Search example: I want to search with, for example, A1_HTTT24, and then get an output as: GLUC_ext = GLUC


Here's what I have done so far:

$database = 'file.txt';
open(Dbase,"<$database") or die "can't open $database $!";
while (my $line = <Dbase>){
chomp $line;

@all = split /\s+/, $line;
($reac,$eqn) = split(':',$all);
chomp $reac;
chomp $eqn;
$reac =~ /([^\s]+)/;
$reac = $1;
$eqn =~ /(^\s+)(.+)(\s\.)/;
$eqn = $2;

#@reac = $reac;
@eqn = $eqn;
#$reac =~ s/\s//g;

}
close(Dbase);

open (DATA,"+>data.txt") or die "Can't open data";
do {
print "reaction name for searching: \n";
$input = <>;
chomp $input;

while (@all){

foreach $r (@reac){
$flag = 0;

foreach $e (@eqn){

if ($r eq $input){
$flag = 1;
last;
print DATA "$r,$eqn{$r}\n";
}else{

print "$input not found!\n";

}
}
}


}

close(DATA);
}until ($input =~ /^\s*$/);
exit(0);


Thanks,

Jamie

In Reply To



(This post was edited by perlfree on Mar 3, 2010, 5:04 PM)


Edit Log:
Post edited by perlfree (Novice) on Mar 3, 2010, 5:04 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