Copyright © tutorialspoint.com

# PERL reverse Function

## Syntax

reverse LIST

## Definition and Usage

In a list context, returns the elements of LIST in reverse order. In a scalar context, returns a concatenated string of the values of LIST, with all bytes in opposite order.

## Return Value

- Returns in Scalar Context: String

- Returns in List Context: List

## Example

Try out following example:

    #!/usr/bin/perl -w

    @array = (2,3,4,5,6,7);
    print "Reversed Value is ", reverse(@array), "\n";
    $string = "Hello World";
    print "Reversed Value is ", scalar reverse("$string"), "\n";

It will produce following results:

    Reversed Value is 765432
    Reversed Value is dlroW olleH

Copyright © tutorialspoint.com