# Perl concise tutorial
#1. perl uses # as a single line comment
# Multi-line comments are enclosed by pod = cut as follows: multi-line comments
= Pod
Multiline comment
= Cut
#1. Variables
# There are only three variables in perl
#1. Common variables (scalar)
#2. Array variables (list)
#3. hash variable (hash table)
# Declaration method
# Scalar
$ A = 1;
$ Scalar = 10;
$ S = "sdsd ";
$ S1 = 'asdasd ';
# Array
Print @ arr = (1, 2, 3, 4, 5, 6 );
& P;
Print @ arr100 = (1 .. 100 );
& P;
# Hash table
Print $ hash = {'a' => "abc", 'B' => "B "};
Print $ hash-> {};
& P;
# Function definition
# Sub funcname {
# The parameter is in @ _.
# @ _ [0] the first parameter
# @ _ [1] The second parameter
# @ _ [2] The third parameter
# And so on
#}
# Function call
# Add a name before the function name &
Sub p {# This function is used to assist printing
& Println;
}
Sub println {
Print "n ";
}
# Regular expression usage (simple exception)
# The regular expression has only five elements: 1. Metadata. 2. Quantifiers. 3. Group. 4. Reverse reference. 5. Literal
# Search
$ Str = 'abc ';
$ Str = ~ /AB. */; # Use. Metadata and * quantifiers
# Match results in $ &
Print $ &;
& P;
$ Str = "abc1234 ";
$ Str = ~ /Abc (d +)/; # metadata d, quantifiers + grouping (d +)
Print $ &; # match all
& P;
Print $1; # First group
& P;
$ Str = 'abcabc1234 ';
$ Str = ~ /(Abc) 1 (d +)/; # literal abc, Group 1 (abc), reverse reference first group 1, metadata d, quantifiers + Group 2 (d +)
Print $ &;
& P;
Print $1;
& P;
Print $2;
# Replacement
& P;
$ Str = 'abcfireabctoadabc ';
$ Str = ~ S/abc // g; # Replace all abc with an empty g switch to replace all without g, and replace only one
Print $ str;