Guys I am writing a program in perl to loop through an array of integers read in from a file line by line, then notice patterns of numbers in each line and output triples(3 of the same numbers occuring consecutively), pairs(only two of the same numbers occuring consecutively) and straights (three numbers occuring consecutively,each proceeding 1 more than the last).
I keep getting this error however:
Now sorted:
1 1 1 3 3 3 4 4 4 7 7 7 9 9 Vulnerable Triples: 4 Pairs: 1 Straights: 0
2 2 2 3 4 5 6 6 6 7 7 7 8 9 Vulnerable Triples: 3 Pairs: 0 Straights: 4
1 2 2 3 3 3 4 5 6 7 8 9 9 9 Vulnerable Triples: 2 Pairs: 1 Straights: 5
1 2 3 3 4 5 5 5 6 7 8 9 9 9 Vulnerable Triples: 2 Pairs: 1 Straights: 5
1 2 3 3 4 4 4 5 6 7 7 8 9 Immune
1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 9 Immune
Gene Analysis complete. 4 vulnerable cases found - Eliminate Immediately!
Use of uninitialized value in numeric eq (==) at main.pl line 90.
Use of uninitialized value in numeric ne (!=) at main.pl line 98.
Use of uninitialized value in numeric eq (==) at main.pl line 90.
Use of uninitialized value in numeric eq (==) at main.pl line 98.
Use of uninitialized value within @nums in subtraction (-) at main.pl line 106.
Use of uninitialized value within @nums in subtraction (-) at main.pl line 106.
Use of uninitialized value in numeric eq (==) at main.pl line 90.
Use of uninitialized value in numeric eq (==) at main.pl line 98.
Use of uninitialized value within @nums in subtraction (-) at main.pl line 106.
Use of uninitialized value in numeric eq (==) at main.pl line 90.
Use of uninitialized value in numeric ne (!=) at main.pl line 98.
Use of uninitialized value in numeric eq (==) at main.pl line 90.
Use of uninitialized value in numeric eq (==) at main.pl line 98.
Use of uninitialized value within @nums in subtraction (-) at main.pl line 106.
Use of uninitialized value in numeric eq (==) at main.pl line 90.
Use of uninitialized value in numeric ne (!=) at main.pl line 98.
Use of uninitialized value in numeric eq (==) at main.pl line 90.
Use of uninitialized value in numeric eq (==) at main.pl line 98.
Use of uninitialized value within @nums in subtraction (-) at main.pl line 106.
I have spent days trying to solve this. Please let me know what I may be doing incorrectly?! Below is the snippet of code that is not working for me.
foreach $line(@lines)
{
chomp $line;
@nums = split / /, $line;
#print "this is nums: @nums\n";
@snums = sort { $a <=> $b } @nums;
#print "this is @snums\n";
$size = @snums;
$pairs = 0;
$straights = 0;
$triples = 0;
#if not equal to 14 characters output vulnerable
if($size == 1)
{
$susceptibility = "";
}
elsif($size != 14 && $size != 1)
{
$susceptibility = "Immune";
print "@snums"."\t".$susceptibility."\n";
}
elsif($size == 14)
{
$i = 0;
#check for gene combinations
#while($i <= $#snums)
for $i(0..$#snums)
{
#Check for triples
if(($snums[$i] == $snums[$i+1]) && ($snums[$i] == $snums[$i+2]
))
{
$triples ++;
}
#Check for pairs
if(($nums[$i] == $nums[$i+1]) && ($nums[$i] != $nums[$i+2])
&& ($nums[$i] != $nums[$i-1]))
{
$pairs ++;
}
#Check for straights
if(($nums[$i] == ($nums[($i+1)]-1)) && ($nums[$i+1] ==
($nums[($i+2)]-1)))
{
$straights ++;
}
}
$susceptibility = "Vulnerable";
$infected ++;
print "@nums"."\t".$susceptibility."\t"." Triples: $triples"." Pairs: $pairs"." Straights: $straights"."\n";
}
}