Sorting:
There is a built-in sort function/subroutine in Perl for sorting array elements. This is done by just writing "sort @name_of_the_array;". But it sorts the elements alphabetically according to their ASCII value. This sort function sorts lexically
Example:
There is a built-in sort function/subroutine in Perl for sorting array elements. This is done by just writing "sort @name_of_the_array;". But it sorts the elements alphabetically according to their ASCII value. This sort function sorts lexically
Example:
use strict;
main(@ARGV);
sub main
{
my @arr = ("abc", "abcd", "defg", "def", "ijklm", "ijkl", "nop", "nop", "aaa", "AAA");
print "before sort : @arr\n"; #before sort : abc abcd defg def ijklm ijkl nop nop aaa AAA
@arr = sort @arr;
print "after sort : @arr\n"; #after sort : AAA aaa abc abcd def defg ijkl ijklm nop nop
}