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