syntax tr///

Documentation for syntax tr/// assembled from the following types:

language documentation Operators

From Operators

(Operators) tr///

my $str = 'old string';
$str ~~ tr/dol/wne/;
say $str# OUTPUT: «new string␤»

tr/// operates on the $_ topical variable and changes it in place. It behaves similar to Str.trans called with a single Pair argument, where key is the matching part (characters dol in the example above) and value is the replacement part (characters wne in the example above). Accepts the same adverbs as Str.trans. Returns the StrDistance object that measures the distance between original value and the resultant string.

my $str = 'old string';
$str ~~ tr:c:d/dol st//;
say $str# OUTPUT: «old st␤»