1 | tr/ab/XY/ translates a to X and b to Y in string $_ |
2 | As for m and s, one can apply tr to a general string with =~ |
3 | $string =~ tr/a-z/A-Z/; # translates letters from lower to upper case in $string |
4 | Note use of - to specify range as in regular expressions, although tr does NOT use regular expressions |
5 | tr can count and return number of characters matched |
6 | $numatoz = tr/a-z//; # $numatoz holds number of lower case letters in $_ |
7 | if final string empty no substitutions are made |
8 | if second string shorter than first, the last character in second string is repeated |
9 | tr/a-z/A?/; # replaces a by A and all other lower case letters by ? |
10 | if the /d option used, unspecified translated characters are deleted |
11 | tr/a-z//d; # deletes all lower case letters |
12 | the /c option complements characters in initial string |
13 | tr/a-zA-Z/_/c; # translates ALL nonletters into _ |
14 | the /s option captures multiple consecutive copies of any letter in final string and replaces them by a single copy |