Implementation of perimeter calculation function.