in reply to Subroutine not correct (I think)

printf OUT "%s to %s Distance=%.5f\n", $data[$i][0], $data[$j][0], $data[$i][2], $data[$j][2], distance(\@coords_i, \@coords_j);

Your printf statement has three placeholders, but you supply five elements of data to be printed.

return sqrt(($x - $x)**2 + ($y - $y)**2 + ($z - $z)**2);

The expression $x - $x will always be zero, as will the others.

Replies are listed 'Best First'.
Re^2: Subroutine not correct (I think)
by jcklasseter (Sexton) on Jun 17, 2015 at 13:10 UTC
    Aren't the printf placeholders for the 3 columns of data? I'm not sure how to fix the formula. I don't know how to iterate very well, at all. Any suggestions?

      There are five items of data in the list passed to sprintf, not three. They are:

      1. $data[$i][0]
      2. $data[$j][0]
      3. $data[$i][2]
      4. $data[$j][2]
      5. distance(\@coords_i, \@coords_j)

      Therefore, your format string in the sprintf call should have enough placeholders (five!) to match this list and not merely the three currently present.