#!/usr/local/bin/perl -w #Author: Shraddha Kulkarni use strict; print "This script calculates area of the polygon enclosed in given points.\nEnter coordinates of points in clockwise sense.\n\n"; my @coords; my $area=0; while(1){ print "Enter x coordinate: "; my $x=; last if ($x eq "\n"); print "Enter y coordinate: "; my $y=; last if ($y eq "\n"); print "Press Enter to get the area of polygon or Enter " if(@coords>=3); print "Next Point \n"; push @coords,$x; push @coords,$y; } if(@coords<3){ print "A polygon has at least three points.. try again"; exit; } for (my $i=0;$i<@coords;$i=$i+2){ my $j=$i+1; my $k=$i+2; my $l=$i+3; $j=$j-(@coords) if($j>=@coords); $k=$k-(@coords) if($k>=@coords); $l=$l-(@coords) if($l>=@coords); $area += ($coords[$k]*$coords[$j]-$coords[$i]*$coords[$l])/2; } print "Area - $area";