Sorts the specified array using the specified closure for comparisons.
&closure - the comparison function to use.
When called, the closure will have the two values to compare in the $1 and $2 variables. Based on the comparison of $1 and $2 the closure should do one of the following:
Comparison Return Value $1 < $2 return a positive value $2 == $2 return 0 $1 > $2 return a negative value
@array - the array to sort
A reference to the sorted @array.
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')