R
rajasekaran.natarajan
the code is a part of a large program, in which everythign works fine
except the IF BLOCK why? whats wrong with that. I tried everything I
can, yesterday. But no use. I do not know debugging But I have inserted
print commands to check what is going on. only IF block is not working.
WHY?
1. It is executing with a message saying
MESSG:use of Uninitiallized value (refering to $cn[$s1]) at line no#
but it can not be becuase the intial shortest is very high and the all
calculated $dist is less than 30. It *HAS* to execute the IF block and
assign the $cn[$s1] some value.
2. All calculated $dist are less than 30. but when I see the output it
is printing
1,,10000
2,,10000
3,,10000
it says it is not assigning $dist to $shortest by IF loop WHY? WHY?
WHY?
my $shortest=100000;
#assiging initial values#
foreach my $s1 (@set1){
#from array set1, the sample point is s1#
foreach my $s2 (@set2) {
#from array set2 the sample point is s2#
($x1,$y1,$z1) = ($g{$s1}->{x},$g{$s1}->{y},$g{$s1}->{z});
#this picks the coordinates for point s1 from hash#
($x2,$y2,$z2) = ($g{$s2}->{x},$g{$s2}->{y},$g{$s2}->{z});
#this picks the coordinates for point s2 froma hash #
my $dist= sqrt(($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2);
#thiscalculate dist bet s1 and s2 #
if($dist le $shortest){
# if the dist is .LE. the shortest then do this #
$shortest = $dist;
#assign the calculated dist as the new shortest#
$cn[$s1] = $s2;
# store this particular point s2 in cn#
}
}
print OUT "$s1,$cn[s1],$shortest\n";
# print s1 and closest point s2 then the distance #
$shortest = 100000; #initialize for next iteration #
}
except the IF BLOCK why? whats wrong with that. I tried everything I
can, yesterday. But no use. I do not know debugging But I have inserted
print commands to check what is going on. only IF block is not working.
WHY?
1. It is executing with a message saying
MESSG:use of Uninitiallized value (refering to $cn[$s1]) at line no#
but it can not be becuase the intial shortest is very high and the all
calculated $dist is less than 30. It *HAS* to execute the IF block and
assign the $cn[$s1] some value.
2. All calculated $dist are less than 30. but when I see the output it
is printing
1,,10000
2,,10000
3,,10000
it says it is not assigning $dist to $shortest by IF loop WHY? WHY?
WHY?
my $shortest=100000;
#assiging initial values#
foreach my $s1 (@set1){
#from array set1, the sample point is s1#
foreach my $s2 (@set2) {
#from array set2 the sample point is s2#
($x1,$y1,$z1) = ($g{$s1}->{x},$g{$s1}->{y},$g{$s1}->{z});
#this picks the coordinates for point s1 from hash#
($x2,$y2,$z2) = ($g{$s2}->{x},$g{$s2}->{y},$g{$s2}->{z});
#this picks the coordinates for point s2 froma hash #
my $dist= sqrt(($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2);
#thiscalculate dist bet s1 and s2 #
if($dist le $shortest){
# if the dist is .LE. the shortest then do this #
$shortest = $dist;
#assign the calculated dist as the new shortest#
$cn[$s1] = $s2;
# store this particular point s2 in cn#
}
}
print OUT "$s1,$cn[s1],$shortest\n";
# print s1 and closest point s2 then the distance #
$shortest = 100000; #initialize for next iteration #
}