e.g.
Mass Time
100.20 0.55
150.34 0.23
223.45 1.22
223.44
####
database.txt:
Mass Time Name Type
223.41 1.20 John Boy
111.23 5.21 Betty Girl
100.25 0.56 Ken Boy
.
.
.
####
e.g. for the above userinput, it will return this values in new textfile
Mass Time Name Type
100.20 0.55 Ken Boy
223.45 1.22 John Boy
223.44 John Boy
####
#### Put User input values into hashes in order to search database###
open (CURINFILE,'database.txt') or die $!;
while ()
{
open (INPUTFILE,'userinput.txt') or die $!;
while (my $line=) {
chomp($line);
(my $massinput,my $rtinput) = split /\t/, $line;
$hash{$massinput} = $rtinput;
}
use Data::Dumper;
print %hash; #test if userinput values are stored
####### Specify tolerance (user input) ###############
print "\n Set desired tolerance\n ";
print "-------------------------- ";
print "\n Mass tolerance: ";
$masstoleranceinput = ;
chomp $masstoleranceinput;
print " Time tolerance: ";
$rttoleranceinput = ;
chomp $rttoleranceinput;
######### Start Search Database ############
push @full_data , [split /\t/] while ();
open OUT1, ">$path/Results.txt" or die "error couldn't open output file";
print OUT1 "Mass\tTime(Min)\tName\tType\n";
for $arr_ref1(@full_data)
{
for my $index1 (1) #mass
{
for my $index3(2) #Time
{
for my $index2 (0) #Name
{
for my $index4 (3) #Type
{
$name1 =$$arr_ref1[$index2];
$mode = $$arr_ref1[$index4];
# Mass (+/- tolerance set by user)
$mass1 = $$arr_ref1[$index1];
$masst1 = $$arr_ref1[$index1] + $masstoleranceinput;
$masst2 = $$arr_ref1[$index1] - $masstoleranceinput;
# Time (+/- tolerance set by user)
$rt = $$arr_ref1[$index3];
$rt1 = $$arr_ref1[$index3] + $rttoleranceinput;
$rt2 = $$arr_ref1[$index3] - $rttoleranceinput;
# Condition #stuck here
if (( $masst2 <= $massinput && $massinput <= $masst1 ) && ( $rt2 <= $rtinput && $rtinput <= $rt1 ))
{
my $result1 = "$mass1\t$rt\t$name1\t$mode";
print OUT1 $result1;
} #end of if loop
else{
if (( $masst2 <= $massinput && $massinput <= $masst1 ))
{
my $result2 = "$mass1\t$rt\t$name1\t$mode";
print OUT1 $result2;
} #end of if loop
}
} # End of while loop
####
for my $array_input(@userinputdata)
{
$massinput = $$array_input[0];
$rtinput = $$array_input[1];
}