In this chapter you've learned about functions-what they are and how to call them. You saw that you can create your own function or use one of Perl's many built-in functions. Each function can accept any number of parameters which get delivered to the function in the form of the @ array. This array, like any other array in Perl, can be accessed using the array element to access an individual element. ( For instance, $_ [0] accesses the first element in the @ array.) Because Perl parameters are passed by reference, changing the @ array changes the values in the main program as well as the function.
You learned about the scope of variables and how all variables are global by default. Then, you saw how to create variable with local scope using local() and my(). My() is the better choice in almost all situations because it enforces local scope and limits side effects from function to inside the functions.
Then you saw that it was possible to nest function calls, which means that one function can call another, which in turn can call another. You also might call this a chain of function calls. Private functions were introduced next. A private function is one that only can be used inside the function that defines it.
A list of string functions then was presented. These included functions to remove the last character, encrypt a string, find a sub-string, convert array elements into a string, change the case of a string character, and find the length of a string. Examples were shown about how to change a string's characters and how to search a string.
The section on array functions showed that Perl has a large number of functions that deal specifically with arrays. The list of functions included the ability to delete elements, return key, value pairs from associative arrays, reverse an array's elements, and sort an array. Examples were shown for printing an associative array and checking for the existence of an element.