head#
Return the first $size elements of a list.
Synopsis#
my @first = head $size, @list;
my @first = head 2, qw( foo bar baz ); # ('foo', 'bar')
What you get back#
A list of at most $size elements, taken from the start of the
input. If $size is negative, head returns all but the last
-$size elements — useful for dropping a tail.
Examples#
my @r = head 2, qw( foo bar baz ); # ('foo', 'bar')
my @r = head -2, qw( foo bar baz ); # ('foo')
my @r = head 5, qw( a b c ); # ('a', 'b', 'c') — fewer than $size
Edge cases#
$size >= @listreturns the whole list.$size == 0or-$size >= @listreturns the empty list.
Differences from upstream#
Fully compatible with upstream.
See also#
tail— mirror operation, taking from the end.sample— random selection without positional bias.