Prototypes
Explore the concept of Perl function prototypes and how they influence the parser's behavior. Understand how to define prototypes that mimic built-in functions such as push, and discover characters used in prototypes. Learn to avoid errors by steering clear of barewords, indirect objects, and complicated prototypes.
We'll cover the following...
A prototype is a piece of metadata attached to a function or variable. A function prototype changes how Perl’s parser understands it.
Prototypes allow us to define our own functions that behave like built-ins. Consider the built-in push, which takes an array and a list. While Perl would normally flatten the array and list into a single list passed to push, Perl knows to treat the array as a container and doesn't flatten its values. In effect, this is like passing a reference to an array and a list of values to ...