perl-5.38.0
shift ARRAY
shift

Removes and returns the 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 undef if the array is empty.

配列が空なら undef を返します。

Note: shift may also return undef if the first element in the array is undef.

Note: shift may also return undef if the first element in the array is undef. (TBT)

    my @arr  = (undef, 'two', 'three');
    my $item = shift(@arr); # undef

If ARRAY is omitted, shift operates on the @ARGV array in the main program, and the @_ array in subroutines. shift will operate on the @ARGV array in eval STRING, BEGIN {}, INIT {}, CHECK {} blocks.

If ARRAY is omitted, shift operates on the @ARGV array in the main program, and the @_ array in subroutines. shift will operate on the @ARGV array in eval STRING, BEGIN {}, INIT {}, CHECK {} blocks. (TBT)

Starting with Perl 5.14, an experimental feature allowed shift to take a scalar expression. This experiment has been deemed unsuccessful, and was removed as of Perl 5.24.

Perl 5.14 から、shift がスカラ式を取ることが出来るという 実験的機能がありました。 この実験は失敗と見なされ、Perl 5.24 で削除されました。

See also unshift, push, and pop. shift and unshift do the same thing to the left end of an array that pop and push do to the right end.

unshiftpushpop も参照してください。 shiftunshift は、 poppush が配列の右端で 行なうことを、左端で行ないます。