```{index} single: head; List::Util function ``` ```{index} single: List::Util::head; Perl function ``` # head Return the first `$size` elements of a list. ## Synopsis ```perl 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 ```perl 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 >= @list` returns the whole list. - `$size == 0` or `-$size >= @list` returns 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.