@@ -164,59 +164,59 @@ array. This is why the number of elements will turn out to be 1 instead of
164
164
zero as might be expected by the unwary.
165
165
166
166
my @array = []; # assigns empty array as an item in @array
167
- say @array.elems; #= > 1
167
+ say @array.elems; #- > 1
168
168
169
169
Whereas querying the number of elements of the empty array directly returns
170
170
zero as expected:
171
171
172
- say [].elems; #= > 0
172
+ say [].elems; #- > 0
173
173
174
174
This can be more clearly seen by calling the C < .perl > method on the object:
175
175
176
176
my @array = [];
177
- say @array.perl; #= > Array.new([]) # an array containing an empty array
177
+ say @array.perl; #- > Array.new([]) # an array containing an empty array
178
178
179
179
in contrast to:
180
180
181
181
my @array = ();
182
- say @array.perl; #= > Array.new() # a truly empty array
182
+ say @array.perl; #- > Array.new() # a truly empty array
183
183
184
184
Note that this is I < also > the behaviour in Perl 5:
185
185
186
- perl -E "say scalar(my @array = [])" #= > 1
187
- perl -E "say scalar(my @array = ())" #= > 0
186
+ perl -E "say scalar(my @array = [])" #- > 1
187
+ perl -E "say scalar(my @array = ())" #- > 0
188
188
189
189
= head2 Referencing the last element of an array
190
190
191
191
In Perl 5 one could reference the last element of an array by asking for the
192
192
"-1th" element of the array, e.g.:
193
193
194
194
my @array = qw{victor alice bob charlie eve};
195
- say @array[-1]; #= > eve
195
+ say @array[-1]; #- > eve
196
196
197
197
In Perl 6 it is not possible to use negative subscripts, however the same is
198
198
achieved by actually using a function, namely C < *-1 > . Thus accessing the
199
199
last element of an array becomes:
200
200
201
201
my @array = qw{victor alice bob charlie eve};
202
- say @array[*-1]; #= > eve
202
+ say @array[*-1]; #- > eve
203
203
204
204
= head1 Strings
205
205
206
206
= head2 Capitalizing a string
207
207
208
208
In Perl 5 one could capitalize a string by using the C < ucfirst > function
209
209
210
- say ucfirst "alice"; #= > Alice
210
+ say ucfirst "alice"; #- > Alice
211
211
212
212
The C < ucfirst > function does not exist in Perl 6; one needs to use the
213
213
C < tc > method:
214
214
215
- say "alice".tc; #= > Alice
215
+ say "alice".tc; #- > Alice
216
216
217
217
which is equivalent to
218
218
219
- say tc "alice"; #= > Alice
219
+ say tc "alice"; #- > Alice
220
220
221
221
Here, C < tc > means "title case".
222
222
0 commit comments