SoFunction
Updated on 2025-04-13

PERL Script Study Notes

1. When chomp has no parameters, the default parameters will be used and $_ will be operated.
2. Array @array.. can be referenced by $array[number]. $#array.. represents the number of indexes in the array.
3. $! contains error information;
4. The default way to open a file handle is "<" that is, input. The difference between ">>" and ">" is lies in the addition method to operate the file.
if(@ARGV < 2){
die “Not enough arguments\n”;
}
5. select LOG; change the default handle; no need to enter handle parameters in the following output;
print LOG "Hello world!\n";
6. Reopening a handle will close the previous file handle;
7. my @k = keys %hash; my@v = values ​​%hash returns the key value or variable value;
There is a key when judging the existences function in hask, and the delete function deletes the key and value;
8. "." is a wildcard character for metacharacter. The asterisk ("*") matches the previous item 0 times or more (simple quantifier), "+" means one or more, "?" means whether it appears once.
9. "/i" case irrelevant; "/s" matches any symbol; "/x" adds spaces; use "/is" in conjunction;
10. "m//" actually represents general pattern matching "/ /" can also use m(), m{}, m<>.. Similar to "qw//".
11. Word boundary anchoring, \b, is used for words. For example, /\bfred\b/ can match the word fred.
12. Items with names like $1 and $2 that match the same as the bracket logarithm in the pattern;
13. Three special variables ($`, $&, $') are used to indicate where they match, namely left, center and right.
14. "/s" can only be executed once without adding "/g";
Use opposite to if, and a statement can be formed immediately after the control modifier. Elsif is not elseif, and one e is missing;
The break and continue of other languages ​​correspond to next; redo does not perform the next loop of conditional expression, and jumps directly to the top of the loop content.
"file";rename "old","new";link "file";mkdir "file", oct("permission");rmdir "file";chmod 0755, “fred”, “barney”;chown $user, $group, glob “*.o”;utime $now, $ago, glob “*”;
..$where = index($big, $small); is found at the beginning, and index returns 0. If one character is followed, it returns 1, and so on. If the substring does not exist, return -1;rindex...
19.$part = substr($string, $initial_position, $length);
$money = sprintf “%.2f”, 2.49997;
"date";
(undef, $card_num, undef, undef, undef, $count) = split /:/;