Labels: styles use different files for the Learning Program
1. in Perl, the subprogram name and variable name are different namespaces. You can use the same name to name subprograms and variables respectively. However, we do not recommend that you use this method.
2. The definition of subprograms is global. The definition of the front edge will be overwritten after the subprograms with the same name.
3. Define a subroutine
Sub subprogram {
# Body
}
4. Call a subroutine
& Subprogram
5. All subprograms return values. The result of the last row is returned by default.
6. When the subroutine does not define a parameter, the passed parameter is passed to "@ _" by default, and can be accessed through $ _ [0], $ _ [1;
7. Create a private variable in the subroutine
My ($ M, $ N );
My will not change the context of the assignment;
My variable is only used in the innermost statement block where it is located (such as for and foreach). If it is exceeded, it is invalid;
If it is not in any statement block, it is valid for the entire program file and used as the private variable of the entire program file;
My is enclosed by parentheses, and all variables in the brackets are declared. Without parentheses, it is only useful for the variable following it. My ($ M, $ N), my $ m, $ N;
8. Use strict: use more strict syntax rules, which are useful to the current statement block and the remaining parts;
9. If Perl syntactically identifies a subroutine call, it can omit "&". However, when the subroutine name is the same as the Perl built-in function, "&" cannot be omitted;
10. Persistent private variables
Example:
Sub run {
State $ n = 0;# Initialization once, re-execution will be ignored
$ N + = 1;
}
Cannot be used for Array and hash type variables;