Course of Raku / Regexes and grammars / Regexes / Substitution and replacement / Transliteration

Quiz — Substitution

What does the following program print?

my $s = 'hello';
$s ~~ tr/l/L/;
say $s;
0hello
0heLo
1heLLo
0LLLLL

tr/// replaces characters one for one, and unlike s/// it changes every matching character without needing :g. Both ls in hello become L, giving heLLo.

Course navigation

Transliteration   |   Censor a word