Learn about overloading in Perl.

Perl isn’t a pervasively object-oriented language. Its core data types (scalars, arrays, and hashes) are not objects with methods, but we can control the behavior of our own classes and objects, especially when they undergo coercion or contextual evaluation. This is overloading.

Overloading is subtle but powerful. Consider how an object behaves in boolean context. In boolean context, an object will evaluate to a true value unless we overload boolification. Why would we do this? Suppose we’re using the Null Object pattern to make our own objects appear false in boolean context.

Get hands-on with 1200+ tech skills courses.