in reply to how sort works
The compare function is called repeatedly with different elements.
my @numbers = (7, 12, 49, 44); my @sorted = sort { print("Comparing $a with $b...\n"); $a <=> $b } @numbers;
Comparing 7 with 12... Comparing 49 with 44... Comparing 7 with 44... Comparing 44 with 12...
It only does the comparisons it deems necessary. As you can see, 7 was never compared against 49 directly in the example.
Perl currently uses merge sort unless told otherwise.
|
|---|