File tree Expand file tree Collapse file tree 1 file changed +0
-29
lines changed Expand file tree Collapse file tree 1 file changed +0
-29
lines changed Original file line number Diff line number Diff line change @@ -157,35 +157,6 @@ Instead, use an expression that produces a value when you want a value.
157
157
158
158
= head1 Arrays
159
159
160
- = head2 Number of elements in an array when assigning the empty array
161
-
162
- Assigning an empty array to an array saves the empty array as an item in the
163
- array. This is why the number of elements will turn out to be 1 instead of
164
- zero as might be expected by the unwary.
165
-
166
- my @array = []; # assigns empty array as an item in @array
167
- say @array.elems; #-> 1
168
-
169
- Whereas querying the number of elements of the empty array directly returns
170
- zero as expected:
171
-
172
- say [].elems; #-> 0
173
-
174
- This can be more clearly seen by calling the C < .perl > method on the object:
175
-
176
- my @array = [];
177
- say @array.perl; #-> Array.new([]) # an array containing an empty array
178
-
179
- in contrast to:
180
-
181
- my @array = ();
182
- say @array.perl; #-> Array.new() # a truly empty array
183
-
184
- Note that this is I < also > the behaviour in Perl 5:
185
-
186
- perl -E "say scalar(my @array = [])" #-> 1
187
- perl -E "say scalar(my @array = ())" #-> 0
188
-
189
160
= head2 Referencing the last element of an array
190
161
191
162
In Perl 5 one could reference the last element of an array by asking for the
You can’t perform that action at this time.
0 commit comments