File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,25 @@ binding:
156
156
my %h := { a => 'b', c => 'd', e => 'f'};
157
157
say %h; # OUTPUT: «{a => b, c => d, e => f}»
158
158
159
+ Nested hashes can also be defined using the same syntax:
160
+
161
+ my %h = e => f => 'g';
162
+ say %h<e><f>; # OUTPUT: «g»
163
+
164
+ However, what you are defining here is a key pointing to a L < Pair > , which is
165
+ fine if that is what you want, and if your nested hash has got a single key. But
166
+ C < %h<e> > will point to a C < Pair > which will have these consequences:
167
+
168
+ = begin code :skip-test<Illustrates an error>
169
+ my %h = e => f => 'g';
170
+ %h<e><q> = 'k';
171
+ # OUTPUT: «(exit code 1) PairCannot modify an immutable Str (Nil) in block <unit>»
172
+
173
+ This, however, will effectively define a nested hash:
174
+
175
+ m: my %h = e => { f => 'g'};
176
+ say %h<e>.^name; # OUTPUT: «Hash»
177
+ say %h<e><f>; # OUTPUT: «g»
159
178
160
179
If a L < Pair > is encountered where a value is expected, it is used as a
161
180
hash value:
You can’t perform that action at this time.
0 commit comments