Last active
May 10, 2020 20:30
-
-
Save khalidelboray/6881d1333f5c2b2eb79f46d8244515f5 to your computer and use it in GitHub Desktop.
Raku multiple dimensions hash and subscripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| my %hash = | |
| key1 => { | |
| mutual1 => 'value1', | |
| mutual2 => 'value2' | |
| }, | |
| key2 => { | |
| mutual1 => 'value1a', | |
| mutual2 => 'value2a' | |
| }; | |
| # now we want to get the value of mutual1 in (key1,key2) | |
| # a way for doing this is using the hyber op `>>` | |
| say %hash{'key1','key2'}>>.<mutual1>.raku; | |
| # but there is another magical way | |
| # this `%hash` is a multi dimensional hash ( each key hash a hash as a value) | |
| # so what goes for an subscripts with an Array goes for it , try this out | |
| say %hash{'key1','key2';'mutual1'}.raku; | |
| # what about more than one value ? | |
| say %hash{'key1','key2';'mutual1','mutual2'}.raku; | |
| #and so on | |
| # see https://docs.raku.org/language/subscripts#Multiple_dimensions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment