天道酬勤,学无止境

perl tr

perl中tr的研究

There are three modes in perl m//, s///, tr///; I won’t say much about the first two. Here is tr: Many people are used to s///, and find that there are many similarities with tr. They replace the string with the content they want. The important role of tr is "conversion". E.g: Case conversion: $str = "Hello World"; $str =~ tr/a-zA-Z/A-Za-z/; #Here is to convert uppercase to lowercase, and lowercase to uppercase print $str; #output hELLO wORLD Count the number of strings: $str = "Hello World"; my $count=$str =~ tr/az/az/; #Here only counts the number of occurrences of lowercase letters, write

2021-03-26 19:14:04    分类:博客    perl   perl tr   perl学习笔记