performs an alphabetical comparison of $a and $b
$a - any scalar, converted to a string
$b - any scalar, converted to a string
A value based on comparing $a and $b
Value Description 0 $a is equal to $b < 0 $a is less than $b > 0 $a is greater than $b
sub caseInsensitiveCompare { $a = lc($1); $b = lc($2); return $a cmp $b; } @array = @("zebra", "Xanadu", "ZooP", "ArDvArKS", "Arks", "bATS"); @sorted = sort(&caseInsensitiveCompare, @array); println(@sorted);
@('ArDvArKS', 'Arks', 'bATS', 'Xanadu', 'zebra', 'ZooP')