Perl Reverse Sort Method Last Updated : 24 Feb, 2023 Comments Improve Suggest changes Like Article Like Report The article focuses on discussing how to sort an array/ list which consists of integers or strings in reverse order (descending to ascending). Prerequisite: Sorting in Perl. Syntax: reverse sort @array_name; reverse sort (@array_name); This method is a combination of the reverse and sort method of Perl. The reverse method is used to simply reverse a scalar or an array and the sort method is used to sort an array. The reverse sort function combines these two functionalities to sort an array in reverse order. 1. Sorting a List of Numbers Normally Below is the Perl program to sort a list of numbers normally. Perl #!/usr/bin/perl # Sorting Numbers @nums = (5,8,1,2,3); @rev_num = reverse sort(@nums); print("@rev_num"); Output8 5 3 2 12. Sorting a List of Numbers Using Block Below is the Perl program to sort a list of numbers using block. Perl #!/usr/bin/perl @nums = (5,8,1,2,3); @rev_num = reverse sort {$a <=> $b} (@nums); print("@rev_num"); Output8 5 3 2 13. Sorting a List of Numbers Using Subroutine Below is the Perl program to sort a list of numbers using subroutine. Perl #!/usr/bin/perl # Sorting Numbers @nums = (5,8,1,2,3); @rev_num = reverse sort rev_sort (@nums); sub rev_sort{ if ($a < $b){ return -1; } elsif($a == $b){ return 0; } else{ return 1; } } print("@rev_num"); Output8 5 3 2 14. Sorting a List of Strings (All Starts With Same Case) Perl #!/usr/bin/perl @str = ("this","is","to","how","reverse","sort","works"); @rev_str = reverse sort @str; print("@rev_str"); Outputworks to this sort reverse is how Explanation: Here all the string starts with lowercase letters, no mixture has been considered for this purpose. We will use mixtures in later stages. 5. Sorting a List of Strings (Mixed Case) Below is the Perl program to sort a list of strings with mixed case. Perl #!/usr/bin/perl # Sorting String @str = ("This","is","to","How","Reverse","sort","Works"); @rev_str = reverse sort @str; print("@rev_str"); Outputto sort is Works This Reverse How Explanation: Here Perl internally groups those strings which start with Uppercase and sorts them in descending order and the same for the words that start with lowercase letters. Now while printing the entire thing it first prints the reversely sorted lowercase letters then those which start with uppercase letters as the ASCII value of 'a' is 97 and 'A' is 65, as we are sorting reversely that's why the higher ASCII value is being considered as a whole. 6. If Strings are of Mixed Case If we have some strings which are of mixed string, means that if the starting one is lowercase but anyone in the middle or end is uppercase or vice versa the result will be the same as last time only the case of the first letter matters. Below is the Perl program to sort a list of strings if the strings are of the mixed case. Perl #!/usr/bin/perl @str = ("This","iS","tO","How","Reverse","sort","Works"); @rev_str = reverse sort @str; print("@rev_str"); OutputtO sort iS Works This Reverse How Comment More infoAdvertise with us Next Article Perl Reverse Sort Method dwaipayan_bandyopadhyay Follow Improve Article Tags : Perl Perl-method Similar Reads Perl | reverse() Function reverse() function in Perl when used in a list context, changes the order of the elements in the List and returns the List in reverse order. While in a scalar context, returns a concatenated string of the values of the List, with each character of the string in the opposite order. Syntax: reverse Li 1 min read Perl | Reverse an array Reverse an array or string in Perl. Iterative Way: Iterate over the array from 0 to mid of array. Swap the arr[i] element with arr[size-i] element. Perl #Perl code to reverse an array iteratively #declaring an array of integers @arr = (2, 3, 4, 5, 6, 7); # Store length on array in $n variable $n = $ 2 min read Perl | sort() Function sort() function in Perl is used to sort a list with or without the use of method of sorting. This method can be specified by the user in the form of subroutines or blocks. If a subroutine or block is not specified then it will follow the default method of sorting. Syntax: sort List sort block, List 2 min read Perl | Sorting of Arrays Perl has a built-in sort() function to sort an array of alphabets and numbers. When an array is passed to the sort() function it returns a sorted array. Syntax: sort @Array Returns: a sorted array Sorting of Arrays in Perl can be done in multiple ways: Use of ASCII values to sort an Array Use of Com 5 min read C# | Reverse the order of the elements in the entire List or in the specified range List<T>.Reverse Method is used to reverse the order of the elements in the List<T> or a portion of it. There are two methods in the overload list of List<T>.Reverse Method as follows: Reverse() Reverse(Int32, Int32) Reverse() Method This method is used to reverse the order of the e 4 min read Collections.reverseOrder() in Java with Examples The reverseOrder() method of Collections class that in itself is present inside java.util package returns a comparator and using this comparator we can order the Collection in reverse order. Natural ordering is the ordering imposed by the objects' own compareTo method. Syntax: public static Comparat 5 min read Comparator reversed() method in Java with examples The reversed() method of Comparator Interface in Java returns a comparator that imposes the reverse ordering of this comparator. If you use sort method of the array and passes this comparator after applying the reversed method then it will sort the array in reverse order. Syntax: default Comparator 2 min read LINQ | Sorting Operator | Reverse In LINQ, sorting operators are used to rearrange the given sequence in ascending or descending order based on one or more attributes. There are 5 different types of sorting operators are available in LINQ: OrderBy OrderByDescending ThenBy ThenByDescending Reverse Reverse Operator The reverse operato 3 min read Introduction to Sorting Techniques â Data Structure and Algorithm Tutorials Sorting refers to rearrangement of a given array or list of elements according to a comparison operator on the elements. The comparison operator is used to decide the new order of elements in the respective data structure. Why Sorting Algorithms are ImportantThe sorting algorithm is important in Com 3 min read C# | Reverse the order of the elements in the entire ArrayList or in the specified range ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Reverse Method is used to reverse the order of the elements in th 4 min read Like