in reply to Re^2: Subroutine not correct (I think)
in thread Subroutine not correct (I think)

jcklasseter:

Yeah, just get rid of the -$* part. Normally, you'd compute the distance like:

return sqrt( ($x2 - $x1)**2 + ($y2 - $y1)**2 + ($z2 - $z1)**2 );

But another way to think of it would be:

my $dx = $x2 - $x1; my $dy = $y2 - $y1; my $dz = $z2 - $z1; return sqrt( $dx**2 + $dy**2 + $dz**2 );

Your map statement is computing dx, dy and dz (you've just labelled them as x, y and z), so after your map statement, you can just use:

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

Though I'd suggest renaming the variables x, y and z to clarify the code.

...roboticus

When your only tool is a hammer, all problems look like your thumb.