#!/usr/bin/perl @one = ( 2, 5); @two = ( -4, -3); @three = (2, -6); @result = (); $r = &dProduct(\@one,\@two,\@three); print "\n Dot Product = $r \n"; # ------------------------------------------------ # Returns dot product of three vectors. # Takes three pointers to arrays as input # Returns a scalar. sub dProduct { my ($x,$y, $z) = @_; my $sum; my $ct1 = $#{$x} + 1; # items in $x my $ct2 = $#{$y} + 1; # items in $y my $ct3 = $#{$z} + 1; # items in $z return undef if ($ct1 != $ct2) ; for ($i=0;$i<$ct1;$i++) { $sum += $$x[$i] * $$y[$i] * $$z[$i]; } return $sum; }