sub distance($$$$) { my($x1, $y1, $x2, $y2) = @_; return sqrt(($x2 - $x1) ** 2 + ($y2 - $y1) ** 2); }This is for 2D only. Notice that ** is the exponent operator.
Programming Tips - How can I find the distance between two points in Perl?
Date: 2012mar25
Language: Perl
Q. How can I find the distance between two points in Perl?
A. Here's a function for that: