Reprint: http://blog.sina.com.cn/s/blog_4a0824490101hncz.html
(1)/C means to replace the characters that are not matched.
$temp = "Aaaabcdef";
$count = $temp =~tr/a/h/c;
Print "$temp \t$count\n";
Results: Aaaahhhhh 5
(2)/d: Replace all characters on the match
$temp = "Aaaabcdef";
$count = $temp =~tr/a/h/d;
Print "$temp \t$count\n";
Results: Hhhhbcdef 4
(3)/s: Indicates that if there are multiple consecutive characters in the character to be replaced, the redundancy is redundant:
$temp = "Aaaabcdef";
$count = $temp =~tr/a/h/ds;
Print "$temp \t$count\n";
Results: Hbcdef 4
$temp = "Aaaabcdef";
$count = $temp =~tr/a/h/cs;
Print "$temp \t$count\n";
Results: Aaaah 5
=============================================================
Also, let me summarize the usefulness of tr:
$count = $temp =~tr/a//; The number of a in the #表示计算 $temp, $temp does not change the value
$count = $temp =~tr/a/a/; #表示计算 the number of a in the $temp, $temp does not change the value and the meaning above
$temp = "Aaaabcdef";
$count = $temp =~tr/[a-z]/[a-z]/; #表示进行大小写转换
Print "$temp \t$count\n";
results: Aaaabcdef9
if written as $count= $temp =~tr/[a-z]/[a-z]/, then $temp will not change, only the number of capital letters in the $temp is counted .
results: AAAABCDEF9
Usage of TR in Perl (reproduced)