
perlfree
Novice
Mar 3, 2010, 3:56 PM
Post #1 of 6
(3123 views)
|
|
Search and extraction help
|
Can't Post
|
|
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
(This post was edited by perlfree on Mar 3, 2010, 5:04 PM)
|