[Chapter 3] 3.2.126 reverse
Author: Larry Wall, Tom Christiansen & Randal L. Schwartz
Date: 1999-07-02T01:53:23Z

#

| Chapter 3 Functions |

### 3.2.126 reverse

    reverse LIST

In list context, this function returns a list value consisting of the elements of `LIST` in the opposite order. This is fairly efficient because it just swaps the pointers around. The function can be used to create descending sequences:

    for (reverse 1 .. 10) { ... }

Because of the way hashes flatten into lists when passed to (non-hash-aware) functions, reverse can also be used to invert a hash, presuming the values are unique:

    %barfoo = reverse %foobar;

In scalar context, the function concatenates all the elements of `LIST` together and then returns the reverse of that, character by character.

A small hint: reversing a list sorted earlier by a user-defined function can sometimes be achieved more easily by simply sorting in the opposite direction in the first place.

3.2.125 return |  | 3.2.127 rewinddir