Subroutines Versus Functions

A function, in general, is a chunk of code that performs some operation on some form of data. You call, or invoke, a function by naming it and giving it arguments somewhere in your Perl script. Perl then transfers execution to the function definition, performs the operations in that function, and then returns to where the execution left off when the function is done. This is true of any kind of function.

In previous lessons, we've been working a lot with Perl's built-in functions such as print, sort, keys, chomp, and so on. These are functions that are defined by the standard Perl library that you can use anywhere in your Perl programs. Another set of functions are available to you using additional Perl modules or ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition 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.