Reputation: 6012
When I use a regex
as the first argument of trans
, it's OK:
> say 'abc'.trans(/\w <?before b>/ => 1)
1bc
Using a hash
as an argument of trans
is also OK:
> my %h
> %h{'a'} = '1'
> say 'abc'.trans(%h)
1bc
But when I try to use regexes in a hash, it doesn't work:
> my %h
> %h{'/\w/'} = '1'
> say 'abc'.trans(%h)
abc
Upvotes: 2
Views: 119
Reputation: 34130
'/\w/'
is not a regex, it is a string.
my %h{Any}; # make sure it accepts non-Str keys
%h{/\w/} = 1;
say 'abc'.trans(%h)
111
Upvotes: 4