1. command line parameters in Perl:
Perl provides a special built-in array @ argv to store user input parameters from the command line. The function is the same as the command line parameters of C/C ++, but the implementation is not the same; the command line parameters defined in Perl do not contain the Perl program file name after the Perl Command and the Perl Command, that is, do not contain the "Perl program file name", that is, all the parameters in the array @ argv are input by the user on the command line, excluding the "Perl program file name", starting after the "Perl program file name, parameters between the return key are stored in the array @ argv; $ argv [0] stores the first parameter entered by the user; perl5 stores the invocation program name in the special variable $0. Parameters in the command line are separated by spaces;
Each storage unit in the array @ argv stores items separated by spaces in the command line. If there are string parameters on the command line and spaces are required between strings, in this case, use quotation marks to enclose the strings containing spaces. Otherwise, the perl interpreter will interpret these strings as multiple parameters and store them in multiple different storage units of the array @ argv;
When an array @ argv is generated, the file handle argv and the last unit index $ # argv of the array are generated. arrays @ argv can be processed cyclically; if the array @ argv is an empty array, the subscript index of the last storage unit of the array $ # argv is-1, that is, $ # argv =-1; for any empty array, the subscript of the index of the last storage unit of the array is-1;
2. Use the <> file OPERATOR:
In Perl, the <> operator is actually an implicit reference to the array @ argv. its working principle is:
1. When the perl interpreter sees the <> operator for the first time, open the file named $ argv [0;
2. Execute shift (@ argv); that is, move all the elements in the array @ argv forward to a position, and the number of elements in the array is also reduced by 1;
3. <> the operator reads all rows in the file opened in step 1;
4. After reading the interpreter, return to the first step to repeat the operation;
You can use the command line variable as the simple syntax for file table processing as follows:
While (<> );
This line of code is used to open and close the special file handle argv, set the $ argv variable, and read each line in the file. It is really convenient to use the special file handle argv to process the file, however, it is also difficult to read every element in the array @ argv, determine the switch corresponding to each value, and determine when a file needs to be processed;
3. File Buffer settings:
By default, the perl interpreter uses a buffer for the file: $ I = 0;
To tell the perl interpreter not to buffer files, you can use the following methods:
1. Use the select () function to select a specified file as the current default file;
2. Set the system's built-in special variable $ I to 1: $ I = 1;
The system variable $ I will tell the perl interpreter whether to buffer the file regardless of whether it should be buffered. If $ I is a non-zero value, it indicates that no buffer is used; if $ I is 0, the buffer is used. System variables $ I and system variables $ ~ Works with $ ^. When the select () function is not called, $ I affects the current default file;