Basic Perl Objects

The time_hash package has all the ingredients that make up an object. Data and functions act on that data. In Perl, these are called methods; in C++, they are called member functions.

The only problem is that you must manually specify the class variable every time you call a method. It would be nice if you could do that automatically.

The hash knows all about the data contained in it. The only thing it doesn’t know is what methods can be used on that data, and you need that information if you are about to write object-oriented code. Perl solves this problem through the use of the bless function.

This function tells Perl to associate the subroutines (methods) in the current package or, in other words, the package where this ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.