@@ -1116,7 +1116,7 @@ and from processes.
1116
1116
Works in Perl 6, and can also be used as a method. I. e. C < my $x = pop
1117
1117
@a; > and C < my $x = @a.pop; > are equivalent.
1118
1118
1119
- The non-paramater version of C < pop > does not exist. Also, if the array
1119
+ The non-parameter version of C < pop > does not exist. Also, if the array
1120
1120
is empty, a Failure will be returned in Perl 6, which will throw if the
1121
1121
value is actually used in a significant way.
1122
1122
@@ -1492,8 +1492,25 @@ Not documented, but probably hiding in an C<IO> class somewhere.
1492
1492
1493
1493
= item shift
1494
1494
1495
- Works as a method as well as a function. C < shift @a > and C < @a.shift > are
1496
- equivalent.
1495
+ Works in Perl 6, and can also be used as a method. I. e. C < my $x = shift
1496
+ @a; > and C < my $x = @a.shift; > are equivalent.
1497
+
1498
+ The non-parameter version of C < shift > does not exist. Also, if the array
1499
+ is empty, a Failure will be returned in Perl 6, which will throw if the
1500
+ value is actually used in a significant way.
1501
+
1502
+ If you are using only defined values in your array, you can use the C < with >
1503
+ function to handle this case:
1504
+
1505
+ with shift @array -> $shifted {
1506
+ say "shifted '$shifted' of the array";
1507
+ }
1508
+ else {
1509
+ say "there was nothing to shift";
1510
+ }
1511
+
1512
+ The Perl 6 ecosystem has a module C < P5shift > which exports a C < shift >
1513
+ function that mimics the original Perl 5 behaviour as much as possible.
1497
1514
1498
1515
= head2 shm*
1499
1516
@@ -1919,8 +1936,16 @@ Perl 6 version.
1919
1936
1920
1937
= item unshift EXPR, LIST
1921
1938
1922
- Available in Perl 6. Can be used as a method. C < unshift(@a, "blah") > is
1923
- equivalent to C < @a.unshift("blah") > .
1939
+ Works as in Perl 5, as well as being available as a method:
1940
+ C < @a.unshift("foo"); > . I < Note: > the flattening behaviour is different in Perl 6:
1941
+ C < @b.unshift: @a > will unshift C < @a > into C < @b > as a single element. See also the
1942
+ L < prepend method|/type/Array#method_prepend > .
1943
+
1944
+ Also note that C < unshift > in Perl 6 returns the array to which was pushed,
1945
+ contrary to Perl 5 where it returns the new number of elements.
1946
+
1947
+ The Perl 6 ecosystem has a module C < P5shift > which exports a C < unshift >
1948
+ function that mimics the original Perl 5 behaviour as much as possible.
1924
1949
1925
1950
= head2 untie
1926
1951
0 commit comments