next up previous contents
Next: The Binding Operators Up: The Translation Operator (tr///) Previous: The Translation Operator (tr///)

The Translation Options

The translation operator has options different from the matching and substitution operators. You can delete matched characters, replace repeated characters with a single character, and translate only characters that don't match the character list. The translation options are:

Normally, if the match list is longer than the replacement list, the last character in the replacement list is used as the replacement for the extra characters. However, when the d option is used, the matched characters simply are deleted.

If the replacement list is empty, then no translation is done. The operator still will return the number of characters that matched, though. This is useful when you need to know how often a given letter appears in a string. This feature also can compress repeated characters using the s option.

Note UNIX programmers may be familiar with using the tr utility to convert lowercase characters to uppercase characters, or vice versa. Perl now has the lc() and uc() functions that can do this much quicker.


next up previous contents
Next: The Binding Operators Up: The Translation Operator (tr///) Previous: The Translation Operator (tr///)
dave@cs.cf.ac.uk