Solution Review: Calculating Area
Explore how to create and use a Perl package named Triangle. Learn to set member variables with a constructor and calculate the area using a subroutine for object-oriented programming.
We'll cover the following...
We'll cover the following...
Let’s look at the solution first before jumping into the explanation:
Explanation
Line 1:
- We have initialized the package
Triangle.
Line 3 - 17:
- We have defined the constructor and declared the class member variables
_lengthand_height. We shifted the values so that for every object of the class, we can use a new set of variables.
Line 19 - 24:
- We have defined
areasubroutine which is called in line 27 from themain,