diff options
author | Scott Baker <scott@perturb.org> | 2023-02-08 14:52:59 -0800 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-03-30 01:56:51 +0800 |
commit | 705da08ddb0a131173ff13b12db7fb21a2d00a48 (patch) | |
tree | 2f341c2342b13b89650267c15deba5902588de93 /pod | |
parent | 61f7d34e623e08d6cf7fc2bf2c16213c5f03d744 (diff) | |
download | perl-705da08ddb0a131173ff13b12db7fb21a2d00a48.tar.gz |
Update shift() docs with examples
Make wording consistent
Foobar
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perlfunc.pod | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 4d4d172903..8c3da1450f 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -7667,14 +7667,23 @@ X<shift> =for Pod::Functions remove the first element of an array, and return it -Shifts the first value of the array off and returns it, shortening the -array by 1 and moving everything down. If there are no elements in the -array, returns the undefined value. If ARRAY is omitted, shifts the -L<C<@_>|perlvar/@_> array within the lexical scope of subroutines and -formats, and the L<C<@ARGV>|perlvar/@ARGV> array outside a subroutine -and also within the lexical scopes -established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, -C<UNITCHECK {}>, and C<END {}> constructs. +Removes and returns the B<first> element of an array. This shortens the +array by one and moves everything down. + + my @arr = ('cat', 'dog'); + my $item = shift(@arr); # 'cat' + + # @arr is now ('dog'); + +Returns C<undef> if the array is empty. If ARRAY is omitted, C<shift> +operates on the C<@ARGV> array in the main program, and the C<@_> array +in subroutines. + +B<Note:> C<shift> may also return C<undef> if the first element in the array +is C<undef>. + + my @arr = (undef, 'two', 'three'); + my $item = shift(@arr); # undef Starting with Perl 5.14, an experimental feature allowed L<C<shift>|/shift ARRAY> to take a |