@@ -44,14 +44,14 @@ If an L<Enum> is encountered where a value is expected, it is used as a
44
44
hash value:
45
45
46
46
my %h = 'a', 'b' => 'c';
47
- say %h<a>.WHAT; # Pair();
48
- say %h<a>.key; # b
47
+ say %h<a>.WHAT; # Pair();
48
+ say %h<a>.key; # b
49
49
50
50
If the same key appears more than once, the value associated with its last
51
51
occurrence is stored in the hash:
52
52
53
53
my %h = a => 1, a => 2;
54
- say %h<a>; # 2
54
+ say %h<a>; # 2
55
55
56
56
= head1 Looping over hash keys and values
57
57
@@ -60,7 +60,7 @@ keys and values, for instance,
60
60
61
61
my %vowels = 'a' => 1, 'e' => 2, 'i' => 3, 'o' => 4, 'u' => 5;
62
62
for %vowels.kv -> $vowel, $index {
63
- "$vowel: $index".say;
63
+ "$vowel: $index".say;
64
64
}
65
65
66
66
gives output similar to this:
@@ -82,7 +82,7 @@ list of vowels in alphabetical order then one would write
82
82
83
83
my %vowels = 'a' => 1, 'e' => 2, 'i' => 3, 'o' => 4, 'u' => 5;
84
84
for %vowels.sort(*.key)>>.kv -> ($vowel, $index) {
85
- "$vowel: $index".say;
85
+ "$vowel: $index".say;
86
86
}
87
87
88
88
which prints
@@ -111,13 +111,20 @@ is a C<List>.
111
111
Adds the C < @new > elements to the hash with the same semantics as hash
112
112
assignment, but with three exceptions:
113
113
114
- = item the hash isn't emptied first, i.e. old pairs are not deleted.
114
+ = item The hash isn't emptied first, i.e. old pairs are not deleted.
115
115
116
- = item if a key already exists in the hash, and the corresponding value is an
116
+ = item If a key already exists in the hash, and the corresponding value is an
117
117
L < Array > , the new value is pushed onto the array (instead of replacing it).
118
118
119
- = item if a key already exists in the hash, and the corresponding value is not
119
+ = item If a key already exists in the hash, and the corresponding value is not
120
120
an L < Array > , old and new value are both placed into an array in the place
121
121
of the old value.
122
122
123
+ Example:
124
+
125
+ my %h = a => 1;
126
+ %h.push: a => 1; # a => [1,1]
127
+ %h.push: a => [ 1 xx 3 ]; # a => [1,1,1,1,1]
128
+ %h.push: b => 3; # a => [1,1,1,1,1], b => 3
129
+
123
130
= end pod
0 commit comments