Unexpected FAIL with :exists in raku
<a b c>
is a shortcut for qw<a b c>
.
Which will end up as 'a', 'b', 'c'
The way to access a Hash by key is with {}
%h{'a', 'b', 'c'}
Which would be nicer to write as:
%h{<a b c>}
What would be even nicer is to get rid of the {}
%h<a b c>
That is why that is valid Raku syntax.
So when you write this:
%h<$n>
It is basically the same as:
%h{'$n'}
If you are accessing only one element, and it has no whitespace.
Rather than doing this all of the time:
%h{'abc'}
It is much simpler to just use:
%h<abc>
Which is why all of the documentation uses that form.
Similarly these are also the same:
$/{<a b c>}
$/<a b c>
$<a b c>
So if you see $<abc>
it is really looking inside of $/
for the value associate with the key abc
.
There is a lot of syntax reuse in Raku. <>
is one such case.
Note:
You don't need to use .keys
on a Hash with ∈
.
'B' ∈ %h; # True
(Since Raku uses different operators for different operations, it is rare that you would have to do such data massaging.)
You put matches in Str
context by using ~, but I think the problem is your case is that you're using literal quotes <>
for a variable. %h<$n>
returns the value corresponding to the literal key $n. You need to use %h{$n} to retrieve the value corresponding to the content of $n
. Also, if $n contains a Match
it will be put in Str context, so that should work.