Eugene Barsky
Eugene Barsky

Reputation: 6012

Trans, hash, and character classes in Perl 6

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

Answers (1)

Brad Gilbert
Brad Gilbert

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

Related Questions