Summary

Perl supports user-definable functions, called subroutines or subs, that behave just like the built-in functions: They can take arguments, do work, and then return values to the caller if necessary. Perl subroutines can call other subroutines and even themselves. Perl also allows you to declare variables private to a subroutine (or any block of code) and create self-contained pieces of code that can then be reused.

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