Method-Function Equivalence

Learn the different ways to call a function in Perl.

Perl’s object system is deliberately minimal. A class is a package, and Perl doesn’t distinguish between a function and a method stored in a package. The same built-in, sub, declares both. Perl will happily dispatch to a function called as a method. Likewise, we can invoke a method as if it were a function—fully qualified, exported, or as a reference—if we pass in our own invocant manually.

Invoking the wrong thing in the wrong way causes problems.

Caller side

Consider a class with several methods:

Get hands-on with 1200+ tech skills courses.