I know this question may have been asked a million times but I am stumped. I have an array that I am trying to sort. The results I want to get are
A
B
Z
AA
BB
The sort routines that are available dont sort it this way. I am not sure if it can be done. Here's is my perl script and the sorting that I am doing. What am I missing?
# header
use warnings;
use strict;
use Sort::Versions;
use Sort::Naturally 'nsort';
print "Perl Starting ... \n\n";
my @testArray = ("Z", "A", "AA", "B", "AB");
#sort1
my @sortedArray1 = sort @testArray;
print "\nMethod1\n";
print join("\n",@sortedArray1),"\n";
my @sortedArray2 = nsort @testArray;
print "\nMethod2\n";
print join("\n",@sortedArray2),"\n";
my @sortedArray3 = sort { versioncmp($a,$b) } @testArray;
print "\nMethod3\n";
print join("\n",@sortedArray3),"\n";
print "\nPerl End ... \n\n";
1;
OUTPUT:
Perl Starting ...
Method1
A
AA
AB
B
Z
Method2
A
AA
AB
B
Z
Method3
A
AA
AB
B
Z
Perl End ...