Some knowledge of scalar operators and Perl


1. Perl makes general variablesscalar, the direct quantity that this variable can refer to includes two types: digital direct quantity; String direct quantity.

a) Representation of string:
Single quotation mark, the meaning of the string in single quotation mark is intuitive, and there is no need to calculate the variable value and escape character;
Double quotation marks. You need to find the variable value and escape character value.
If you need to eliminate it, you usually need to add a backslash before it, and the single quotation mark or double quotation mark also needs to be added.

b) In addition, QQ or Q can be used instead of double quotation marks or single quotation marks respectively, and the delimiters can be paired (), < >, {}, [], etc.

2. Scalar variable

$plus variable name (array uses @, hash structure uses%); Variable names are case sensitive; Do not declare before using scalar, but initialization is required.

Some special scalar variables:
$_, $ “, $/, $2, $$, $!, their values are usually used as” default “. For example, $is used as the default value of output; $! Is used as the default value of error.

3. Expressions andoperator

1) , warning in Perl #/ usr/bin/perl/- W, or use warnings;
2) . number operator: divide /, find the remainder%, take the power 4 * * 3 = 64
3) String operator: juxtaposition operator ($C = $A. $B;) The interpolation and substitution of variables in double quotation marks can also be used for juxtaposition operation. If you cancel the $and add a backslash before it. Repeat operator x (e.g. $line = “” x 7)
4) Operator with name: int takes integer part; Length takes the length; Convert LC to lowercase; Convert UC to uppercase; Rand is a random number from 0 to the parameter value; COS, more perldoc
5) Angle bracket operator: < > read a line from the handle, such as < stdin > read a line from the keyboard of the standard input device, < File > read a line from the file handle, chomp $line; Remove end line breaks.

Recommended Today

Interview questions I encountered

I was looking for a job recently, so I recorded the interview questions I encountered and the answers I sorted out. – vue Does vue-router know? What are the different modes?……… vue-router Vue-router is the path manager of Vue's deeply integrated single-page application. In Vue's single-page application, it establishes the mapping relationship between url and […]