Day 11. Creating and Using Subroutines

We'll finish up your lesson on the core of the Perl language today with a discussion of subroutines, functions, and local variables. With subroutines you can collect bits of commonly used code into a single operation, and then perform that operation at different times in your script—the same way you use the built-in Perl functions.

The specific things you'll learn about include

  • The differences between user-defined subroutines and Perl's standard functions

  • How to define and call simple subroutines

  • Using variables local to subroutine definitions

  • Returning values from subroutines

  • Passing arguments to subroutines

  • Using subroutines in different contexts

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.