Perl Shift
Perl shift function is similar to perl pop and opposite to Perl Push. It removes and returns the first element of an array, shortening the dimension of the array with 1. Perl pop removes the last element in the array and Perl shift removes the first element.
Perl Shift Syntax
pop (ARRAY) pop
Perl Shift Examples
!/usr/bin/perl use strict; use warnings; my @array = (1, 2, 3, 4); my $size = shift (@array); print "\$size = $size, \@array = @array\n";
The output of the above code is:
$size = 1, @array = 2 3 4
Post your Answer