Hour 8. Functions

Almost all computer languages support functions. A function is a group of code that can be called by name to do some work and then return some value. You've been using functions throughout this book; for example, you've used print, reverse, sort, open, close, split, and so on. They are Perl's built-in functions.

Perl also allows you to write your own functions. In Perl, user-defined functions are called subroutines, or subs. Like Perl's built-in functions, user-defined functions can take arguments and return values to the caller.

Perl also supports the concept of scope. Scope determines the set of variables visible to the program at a given time. Because of Perl's scope, you can write functions that can behave autonomously ...

Get Sams Teach Yourself Perl in 24 Hours 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.