Perl shift function

One very useful function in Perl is shift.

Larry you did it again.

The shift function moves the whole array to the left and will return the scalar value (first array element). As you may guess if the array was empty originally, shift will return undef.

After the operation, the array will be one element shorter.

The example:

my @words = ('Give', 'Me', 'Coins');

my $first = shift @words;

print "$first\n";     # Give

print "@words\n";     # Me Coins

tags: & category: -