我在下面运行代码来对字符串进行排序,但没有得到预期的结果。
代码:
use warnings;
use strict;
my @strArray= ("64.0.71","68.0.71","62.0.1","62.0.2","62.0.11");
my @sortedStrArray = sort { $a cmp $b } @strArray;
foreach my $element (@sortedStrArray ) {
print "\n$element";
}
结果:
62.0.1
62.0.11 <--- these two
62.0.2 <---
64.0.71
68.0.71
预期结果:
62.0.1
62.0.2 <---
62.0.11 <---
64.0.71
68.0.71