To sort a string array in Perl in dictionary order, you can use the `sort` function. To sort in descending order, you can use the `sort` function with a custom comparator or reverse the array after sorting.
In this example,
@words = ("banana", "apple", "orange", "grape");
@words = sort @words;
print "Sorted Array Ascending:\n";
foreach $word (@words) { print "$word\n"; }
Sorted Array Ascending: apple banana grape orange
In this example,
@words = ("banana", "apple", "orange", "grape");
@words = sort { $b cmp $a } @words;
print "Sorted Array Descending:\n";
foreach $word (@words) { print "$word\n"; }
Sorted Array Descending: orange grape banana apple
In this tutorial, we learned How to Sort a String Array in Dictionary Order in Perl language with well detailed examples.