Hi,
I have manage to improve the program and reduce the weird loopings based on your advice. I am kind of stuck at the if condition part, in which I am unsure if it is the correct way to search for the data. I hope I am in the correct direction.
while (<LIBRARYDATA>)
{
#add the name, mass, rt(time) and type to an array
chomp $_;
my @columns = split (/\t/, $_);
my $keyname = $columns[0];
my $keymass = $columns[1];
my $keytime = $columns[2];
my $keytype = $columns[3];
my $key = "$keymass"."\t"."$keytime"."\t"."$keyname"."\t"."$keytyp
+e"."\n";
# Mass (to allow range for user to search based on tolerance they
+input)
$masst1 = $keymass + $masstoleranceinput;
$masst2 = $keymass - $masstoleranceinput;
for ($keymass)
{
for ($keytime)
{
if (defined ($keytime) && defined ($rtinput)) #skip those with bl
+ank cells at "Time" column
{
#allow user to choose time range based on tolerance they set
$rt1 = $keytime + $rttoleranceinput;
$rt2 = $keytime - $rttoleranceinput;
#match according to mass and time against library
if (( $masst2 <= $massinput && $massinput <= $masst1 ) && ( $r
+t2 <= $rtinput && $rtinput <= $rt1 ))
{
print OUT1 "$massinput\t$rtinput\t\t$key";
}
}
else #for those cells at "Time" column that is left blank, go
+to this loop where only mass is being matched
{
#match against mass only
if (( $masst2 <= $massinput && $massinput <= $masst1 ))
{
print OUT1 "$massinput\t$rtinput\t\t$key";
}
}
}
}
}
rtinput and massinput is key in by user, in which sometimes the rtinput will be leave blank. $masstoleranceinput and $rttoleranceinput is also by user input.
LIBRARYDATA refer to the data that I want to match the user inputs with. Some values under "Time" will be blank.
_LIBRARYDATA_
Name Mass Time Type
John 223.41 1.20 Boy
Betty 111.23 Girl
Ken 100.25 0.56 Boy
.
.
.
_INPUTDATA_
e.g.
Mass Time
100.20 0.55
150.34 0.23
223.45 1.22
223.44
The problem I have here is that there will be error once it pass through the first if loop where the error stated that it is unable to do calculation if the value is left blank. Since I have add in that if the values is defined, then continue, otherwise, skip to the next if condition which is just to compare the mass alone.
So the output I get is that I am only able to print those that contain all values. Those lines that has the time (left empty) could not be printed out.
So did I miss out something which cause the error and prevent those (with the value of "Time" left blank) from printing out?
|