Skip to content

Commit 6457dcd

Browse files
dumarchieJJ
authored andcommitted
Add (references to) and improve examples
1 parent 138ffa8 commit 6457dcd

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

doc/Type/Hash.pod6

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ L<named arguments|/type/Capture> and as such won't end up in the C<Hash>:
345345
Use the corresponding L<subroutine|/language/independent-routines#sub_push> to
346346
catch this kind of mistake:
347347
348+
push my %h, f => 7;
348349
CATCH { default { put .message } };
349-
push my %h, f => 7; # OUTPUT: «Unexpected named argument 'f' passed␤»
350+
# OUTPUT: «Unexpected named argument 'f' passed␤»
350351
351352
Also note that push can be used as a replacement for assignment during hash
352353
initialization very useful ways. Take for instance the case of an inverted

doc/Type/independent-routines.pod6

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,9 @@ Defined as:
11771177
Calls method L<C<pop>|/routine/pop> on the container, which is supposed to
11781178
remove and return the last element, or fail if the container is empty.
11791179
1180+
See the documentation of the L<C<Array> method|/type/Array#method_pop> for an
1181+
example.
1182+
11801183
=head2 sub shift
11811184
11821185
Defined as:
@@ -1186,6 +1189,14 @@ Defined as:
11861189
Calls method L<C<shift>|/routine/shift> on the container which is supposed to
11871190
remove and return the first element, or fail if the container is empty.
11881191
1192+
Example:
1193+
1194+
my @foo = <a b>;
1195+
while my $value = shift @foo {
1196+
say $value;
1197+
}
1198+
# OUTPUT: «a␤b␤»
1199+
11891200
=head2 sub push
11901201
11911202
Defined as:
@@ -1202,6 +1213,9 @@ add C<b> or the values in C<|@b> to the end of an array. If C<b> is a C<Slip>,
12021213
the container is supposed to add the values produced by
12031214
L<C<b.iterator>|/routine/iterator>.
12041215
1216+
See the documentation of the L<C<Hash> method|/type/Hash#method_push> for an
1217+
example where the subroutine form is useful.
1218+
12051219
=head2 sub append
12061220
12071221
Defined as:
@@ -1224,9 +1238,10 @@ values of a C<Hash>. Whereas L<method append|/type/Hash#method_append> will
12241238
silently ignore literal pairs that are interpreted as named arguments, sub
12251239
C<append> will throw:
12261240
1227-
CATCH { default { put .message } };
12281241
my %h = i => 0;
1229-
append %h, i => (1, 42); # OUTPUT: «Unexpected named argument 'i' passed␤»
1242+
append %h, i => (1, 42);
1243+
CATCH { default { put .message } };
1244+
# OUTPUT: «Unexpected named argument 'i' passed␤»
12301245
12311246
=head1 Control routines
12321247

0 commit comments

Comments
 (0)