trans is a very useful and powerful instrument, but it remains a bit of a mystery for me.
E.g. I still don't understand this phrase from the docs:
In case a list of keys and values is used, substrings can be replaced as well.
What's the algorithm if keys and values are longer than one symbol?
The following test code explores how .trans works with 'conflicting' keys. Why does the 1st pair work differently depending on whether it is alone or accompanied by the 2nd pair?
my Pair @trans =
ab => '12',
bc => '34',
;
my $str = 'ab';
say "both trans: $str.trans(@trans)"; # 13
say "1st trans: $str.trans(@trans[0])"; # 12
Using a hash instead of a list of pairs produces a different result:
my %trans =
ab => '12',
bc => '34',
;
my $str = 'ab';
say "both trans: $str.trans(%trans)"; # 12
(I understand that in hash, pairs can go in any sequence, but in the first example with the list it's the 1st pair, which isn't fully used if the 2nd pair is present)