$ Refers to one, @ refers to a bunch, and % refers to hash
---------------------------------------------------
X string repetition operator. eg: "Fred" x 3 = "fredfred"
------------------------------------------------------
Array:
$ # Index value of the last element of the array name
$ Data name [-1] last element
The pop and push operations are performed in the last segment, while the shift and unshift operations are performed on the leftmost end.
Reverse reverse list element
Sort the list values by sort
$ _ Default variable. eg: Default variable in the foreach Loop
---------------------------------------------
ChildProgram:
& Subroutine call subroutine
The Return Value of the last operation on the automatically generated subroutine. You can also use return.
@ _ List of parameters for storing subprograms (private variables ). $ _ [0] indicates the 1st elements.
@ _ Can also be used to determine the parameter length. Eg: If (@_! = 2 ){}
The private variable identifier of the my subroutine.
State can retain the value of the variable during multiple calls of the subroutine, and the function of the variable is limited to the subroutine.
---------------------------------------------------------------------
Input and Output:
<Stdin> Read a row
<> Read the input stream of the program call parameters.
@ Argv list of program call parameters. You can forcibly define the value for <> Read.
Open file handle
Select handle: Change the default file output handle
Die output error message.
$! Information about operating system errors.
--------------------------------
Hash:
$ The hash name {key} accesses the elements in the hash.
% The hash name indicates the entire hash.
Reverse % hash creates a reverse hash
=> The fat arrow is used to create a hash
% Hash = ("A" => 1, "B" => 2, "C" => 3 );
@ Ks = keys % hash
@ Vs = values $ hash
$ COUNT = keys $ hash # obtain the number of hash key values
While ($ key, $ value) = each % hash) {}## each function listing key/value
If (exists $ hash {"key"}) {} check whether a key exists in the hash.
Delete $ hash {"key"} Delete key/value
% Env hash machine system environment hash eg: $ ENV {path}
-------------------------------------
Regular Expression:
M // pattern matching operator, abbreviated as //, or M %
= ~ The binding operator uses the pattern on the right to match the string on the left.
Eg: if ($ so = ~ /\ Brub /){}
Matching results of the $1, $2... Parentheses pattern group.
% + This hash stores the results of regular match. Key is a special tag. Eg:
Use 5.010;
My $ names = 'fred or Barney ';
If ($ names = ~ M /(? <Name1> \ W + )(? : And | or )(? <Name2> \ W + )){
Say "I saw $ + {name1} and $ + {name2 }"
}
$ 'Match the string before the start position.
$ & Match result.
$ 'Match the string from the result to the end position.
S // replacement mode. eg:
S/braney/Fred/# Replace Barney with Fred.
$ _ = "Green scaly din20.ur"
S/(\ W +)/$2, $1/; # Replace it with "scaly, green dinosaur"
@ Fields = Split/separator/, $ string;
Eg: My @ ARGs = Split/\ s +/, $ some_input;
My @ fields = split; # by default, it is separated by blank characters $ _;
My $ result = join $ glue, @ pieces;
$ ^ I the default value is UNDEF, And the backup file extension
-----------------------------------------
Unless (if antisense), unless-esle, until (while antisense), if-elsif,
For, foreach
Loop Control:
Last: Terminate the loop immediately (break)
Next: end the current iteration (continue)
Redo: returns the top of the loop.
--------------------------------
Glob: My @ all_files = glob "*"; # obtain all the files in the current directory and sort them alphabetically.
Abbreviation: My @ all_files = <*>;
Open Handle
Opendir directory handle: Open the directory handle
Readdir directory handle: Read directory handle
Unlink parameter list: delete a file
Eg: unlink glob "*. txt" # Delete the *. txt file
Rename "old", "new" RENAME
Mkdir directory name, 0755: create directory
Rmdir directory name: delete directory
Chmod 0755 "Fred", "Barney";: Permission to modify files or directories
Chown $ user, $ group, glob "*. txt";: Change the Affiliation
Utime $ now, $ ago, glob "*. txt";: Modify the timestamp
-------------------------------------
$ Where = index ($ total, $ sub); # index the position where the string appears for the first time
$ Where1 = index ($ total, $ sub, 2) # search from 2nd positions
The position where the rindex function returns a string (also from the beginning ),
The third parameter is to limit the maximum position returned.
substr string, starting position (-1 indicates the last character), length (omitted)
substr can be assigned a value and replaced by a regular expression. Eg:
substr ($ string, 0, 5) = "goodbye ";
substr ($ string,-20) = ~ S/Fred/Barney/g;
<=> compare two numbers and return-1, 0, or 1.
CMP comparison string
$ hash {$ A }<=>$ hash {$ B}
eg:
my @ temp = QW/4 3 2 0 9 6 5 1 /;
my @ result = sort {$ A <=> $ B} @ temp;
------- --------------------------
~~ Intelligent Matching operator (5.10)
1. Replace = ~
2.% hash ~~ /Pattern/traverse all the keys in the hash and match them one by one. If the key is successfully stopped, true is returned.
3. @ enum1 ~~ @ Enum2 array equal
4. @ Enum ~~ $ Num: determines whether $ num is in @ enum. The order is interchangeable.
Given ($ flag ){
When (/Fred/I) {say 'name has Fred in it '}
When ('fred ') {say 'name is Fred '}
Default {say "I don't see a Fred "}
}
Foreach (@ names ){
When (){}
When (){}
Default {}
}
---------------------------------
$ The number of processes currently running.
.
$ @ Eval indicates the error message when an error occurs in the expression.
--------------------------------
= ~ Binding Operator
~~ Only matching Operators