12.1 Parameters of Functions

12.1  Parameters of Functions

 Strictly speaking, Perl functions have only one formal parameter. This formal parameter is a special list variable available inside the function text. This formal parameter is available implicitly inside the function without the author of the function having to do anything. The parameters with which a function is called are put in a single list before being passed to the called function. In other words, if we want to interpret strictly, we can say that each function is called with only one actual parameter which is in the form of a list. We will see that this simple mechanism of parameter passing is quite powerful and allows us to simulate writing three types of functions as far as the nature of the formal parameters is concerned:

  Functions with no formal parameter,

  Functions with an arbitrary number of “formal parameters”, and

  Functions with a specified number of “formal parameters.”

We will look at these three types of functions in the rest of this section with examples. In Chapter 1, we saw examples of the first two types of functions.