summaryrefslogtreecommitdiff
path: root/pod
diff options
context:
space:
mode:
authorScott Baker <scott@perturb.org>2023-02-08 14:39:02 -0800
committerYves Orton <demerphq@gmail.com>2023-03-30 01:56:51 +0800
commit61f7d34e623e08d6cf7fc2bf2c16213c5f03d744 (patch)
tree18b476aa6d6f7e754a0a222c798be42dadb57d25 /pod
parentd31803ec1abbb4a62f5d68ccd4d3efe312c0cefa (diff)
downloadperl-61f7d34e623e08d6cf7fc2bf2c16213c5f03d744.tar.gz
Update pop() docs with examples
Diffstat (limited to 'pod')
-rw-r--r--pod/perlfunc.pod21
1 files changed, 15 insertions, 6 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 5a26941e75..4d4d172903 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -6086,14 +6086,23 @@ X<pop> X<stack>
=for Pod::Functions remove the last element from an array and return it
-Pops and returns the last value of the array, shortening the array by
+Removes and returns the B<last> element of the array, shortening the array by
one element.
-Returns the undefined value if the array is empty, although this may
-also happen at other times. If ARRAY is omitted, pops the
-L<C<@ARGV>|perlvar/@ARGV> array in the main program, but the
-L<C<@_>|perlvar/@_> array in subroutines, just like
-L<C<shift>|/shift ARRAY>.
+ my @arr = ('cat', 'dog', 'mouse');
+ my $item = pop(@arr); # 'mouse'
+
+ # @arr is now ('cat', 'dog')
+
+Returns C<undef> if the array is empty. If ARRAY is omitted, C<pop> operates on
+the L<C<@ARGV>|perlvar/@ARGV> array in the main program, but the
+L<C<@_>|perlvar/@_> array in subroutines.
+
+B<Note:> C<pop> may also return C<undef> if the last element in the array
+is C<undef>.
+
+ my @arr = ('one', 'two', undef);
+ my $item = pop(@arr); # undef
Starting with Perl 5.14, an experimental feature allowed
L<C<pop>|/pop ARRAY> to take a