I. subaccountProgramReferences:
In Perl, you can not only create references to scalar variables, array variables, and hash variables, but also create references to subprograms. References to subprograms are similar to function pointers in C/C ++; the constructor is as follows:
$ Pointer_to_sub = sub {# function body };
In this way, a reference to anonymous subprograms is established. The syntax for calling subprograms through subprograms is as follows:
& $ Pointer_to_sub (parameter list );
1. subroutine template:
Sometimes different subprograms can be created by returning different subprograms for reference, so that the operation can be templated, which is similar to the callback function in C/C ++, that is, the callback function;
2. arrays and subprograms:
Since the array @ _ is a one-dimensional array, no matter how many arrays are passed to the subroutine, the perl interpreter will convert all the arrays you pass into scalar values, then store these scalar values to the array @ _ in the order you pass. Similarly, if an array is returned in the return value, no matter how many sub-arrays are packed into a list, the perl interpreter converts these sub-arrays into scalar values and stores them in a one-dimensional array for the subroutine to return. Therefore, if you obtain the parameter list value in the form of a statement such as my (@ A, @ B) = @ _;, all array values are assigned to the array @, array @ B is an empty array, Because array @ _ is a one-dimensional array;
Therefore, when passing an array to a subroutine, pay attention to the following points:
◆ When the parameters passed to the subroutine are multiple arrays, you must use array references;
◆ Do not try to use the statement processing parameters such as @ array1, @ array2,..., @ arrayn) = @ _; In the subroutine unless you want
Set all parameters to a long array;