Most statement expressions in the Perl language are followed by a semicolon, separating the different Perl statements.
The Perl interpreter can compile and run these two actions at a time. Perl uses a pair of anti-quotes "'" to indicate running external commands.
Scalars include both numbers and strings.
In Perl, the numbers are stored in a "double-precision floating-point number" format, and integer constants are converted to equivalent floating-point numbers.
Perl allows the insertion of the "_" delimiter between digital direct quantities. And for a number other than the decimal (decimal). Octal (octal) begins with "O".
Hex (hexadecimal) starts with "0x". Binary binary (binary) starts with "0b".
The number operators include: +,-,*,/,%. Take the mold operation first take the whole again to seek the remainder.
$fred + = 5; $str. = "";
The string length within Perl is unrestricted, from an empty string to an infinitely long.
If there are characters other than ASCII in the source code, use UTF8 should be added, and any Unicode support will be added.
A string within a single quotation mark does not appear to have special characters, except for single quotes "'" and "/", and other characters represent themselves.
A string within double quotation marks that can represent multiple special characters and support variable interpolation.
String operators are: string connectors. ", the string repeats the operator" X ". Indicates that repeated direct quantities are rounded before they are used, and the decimals are removed directly.
5x4.8 #get "5555"
Perl supports automatic conversion of numbers and strings directly, judging by the operator. A non-numeric part of a string and its subsequent numeric parts are ignored during conversion.
Scalar variable (variable), expressed in dollar sign "$", in order to avoid ambiguity of the variable name, you can use the curly braces {} to enclose the variables name.
The variables in Perl do not need to be initialized, and the initial values are undef. It can then be used to assign values or operations directly.
Operator operators have comparison operators: divide by number or string, = = (eq),! = (NE), < (LT), > (GT), <= (le), >= (GE).
Boolean value: There is no dedicated Boolean type inside Perl. If the number is "0", then false, the others are true. If the string is empty, then false, others are true.
' 0 ' is the only non-empty string that is false.
Control structure in Perl: If...else. while () {...}
The output of the print output is denoted by a double quotation mark "".
Print "The answer is", 6*7, ". \ n"; #也可以用逗号 "," separated, connected together to output.
Perl gets user input <STDIN> generally ends with a newline character.
$line = <STDIN>;
The Chomp () function, which removes line breaks at the end of a string.
Chomp ($text = <STDIN>);
The defined () function is used to determine if a string is an empty string.
A warning function inside Perl. Can be represented at the command line with Perl-w Perl_file. or use warning.
The default variable $_ is used when Perl is not told which variable or value to use.
If print has no parameters, the $_ value is printed by default.
Arrays: Store list variables, you can refer to the entire array with the "@" character multibyte the array name. Array index starting from "0" to "$#+ array name"
$rock [$ #rock] = ' hard rock '; # Assign the last element.
List Direct Quantity: A string of numbers separated by commas in parentheses. or use QW () to indicate that the whitespace character is automatically ignored.
QW (Fred Barney Betty Dino) # represents a list of 4 elements.
or use the range operator: (1..100); #以 "1" is incremented for units.
Array interpolation is also possible within a string with double quotes, noting that the variables in the index values of the array are represented as normal string expressions, and the index values are computed.
$y = 2; $x = "This was $fred [$y-1] ' place" #get $fred [1] of this variable.
In scalar contexts and list contexts, Perl is handled differently.
1) The name of the array in the list context, which returns the list of elements. In a scalar context, returns the number of elements in the array. = [email protected];
2) in scalar context, use the reverse function. $backwards = reverse Qw/yabba dabba doo/; #Assignment oodabbadabbay.
3) Returns the next line of input data in the scalar context,<stdin>. Returns all the remaining rows in the list context,<stdin>.
Pop/push operation: The last variable of an array.
Shift/unshift: The first variable of an array is manipulated.
Splice operation: Arbitrary modification of the array. The first parameter represents the array to modify. The second parameter represents the starting index of the element of the operation. The third parameter represents the length of the operation.
The fourth parameter represents the list to be replaced.
@array = QW (Pebbles Dino Fred Barney)
@removed =splice @array, 1, 2, QW (Wilma); # @array =qw (Pebbles Wilma Barney).
You can use the Foreach Loop body to traverse the values in a list or array, and the list or array or variable is not changed during this process.
foreach $rock (@rocks) {...}
Reverse operator: Returns a list or array in reverse order.
Sort operator: Sorts a list or array by the size of the ASCII code or by the size of the code point of the character.
Each operator: Returns the index value and the value of the next action element in the array.
while (My ($index, $value) = each @rocks) {...}
The Camel spirit of Perl (i)