Perl Packages Part 5 (Object oriented programming)printCity method in the city class, it calls the printProvince method in its parent class - again - treating the parent method as if it were its own. Execution starts at package main. It defines a new city with the following parameters: Victoria, BC and Canada. It is actually calling the new function in the city package. When it enters the new function, it performs initialization and then calls the setProvince method of the province class. When the setProvince function is executed, it sets the PROVINCE and COUNTRY properties. The next statement in the main package calls the printCity method of the $addr object. The printCity function prints out the city name then calls the printProvince function of the province object. The result of this script will be:
City Name: Victoria For
more information on Object Oriented programming in Perl, you can read
the perltoot documentation or look at my self-help
guide. |