Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

reverse

Reverses a list of values or the characters of a string, depending on context.

In list context, collects all items between the stack mark and the current position (flattening any intermediate arrays), reverses their order, and pushes them back. In scalar context, concatenates all items into a single string and reverses the characters. An ASCII fast path reverses bytes in-place; non-ASCII strings are reversed by Unicode code point.

Synopsis

my @rev = reverse @list;
my @rev = reverse 1, 2, 3;       # (3, 2, 1)
my $rev = reverse "Hello";        # "olleH"

See Also

sort