Perl Array Reverse() Function: Quick Tutorial

Person typing on laptop

hackNY.org / Flickr / CC BY-SA 2.0

Perl's reverse() function is used to reverse the order of an array. The function returns a reversed array but does not reverse the array.

@REVERSED_LIST = reverse(@ARRAY); 
reverse()returns @myNames = ('Jacob', 'Michael', 'Ethan', 'Andrew');
@reversedNames = reverse(@myNames); 

@myNamesreverse()@myNames@reversedNames@reversedNames('Andrew', 'Ethan', 'Michael', 'Jacob')

, and @myNames remains the same.