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 = 'reaction_database.txt';
open(Dbase,"<$database") or die "can't open $database $!";
while (my $line = <Dbase>){
chomp $line;
my ($key, $value) = split(/s+:s+/, $line, 2);
chomp $key;
chomp $value;
$key =~ /([^s]+)/;
$key = $1; $value =~ /(^s+)(.+)(s.)/;
$value = $2;
}
close(Dbase);
open (DATA,"+>data.txt") or die "Can't open data $!";
# do {
print "reaction name for searching: \n";
$input = <STDIN>;
chomp $input;
while (defined<$line>){
foreach $k (@value){
if ($key eq $input){
print DATA "$key,$value{$key}\n";
}else{
print "$input not found!\n";
}
}
}
close(DATA);
# }until ($input =~ /^\s*$/);
exit;
Thanks,
Jamie