If you want to sort alphabetically the words with the vowels at the same position, you can make just a very simple change to just one line of the original ST code suggested by choroba:
For each time comparison step in the sorting algorithm, if the vowels compare equal, then#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my @words = qw( fanfare apparate panacea parmesan albatross albacore false vermeil candelabra beans ); say for map $_->[0], sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0]} map [ $_, join q(), /[aeiou]/g ], @words;
return 0. And it returns -1 or +1 in all the other cases. If you get a 0, then the logical or (||) will execute the second part of the sort statement:$a->[1] cmp $b->[1]
to try to see if the whole expression is true. But if you get -1 or +1 with the first part, then the whole expression if already known to be true, so that the second part of the statement will not be executed (short-circuited).$a->[0] cmp $b->[0]
I do not think that the other edge case you mention is compatible with the initial question.
In reply to Re^3: Sorting Strings By Vowel Sequence
by Laurent_R
in thread Sorting Strings By Vowel Sequence
by NewToPerl777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |