| [reply] [Watch: Dir/Any] |
use utf8;
use 5.014;
use warnings;
use List::Util qw/min/;
binmode STDOUT, ':encoding(UTF-8)';
my %order;
{
my $source = join '', 'aáàảãạăaáàảãạăắ',
'ằẳẵặâấầẩẫậbcdđeéèẻẽẹêếềểễ',
'ệfghiíìỉĩịjklmnoóòỏõọôốồổ',
'ỗộơớờởỡợpqrstuúùủũụưứừửữự',
'vwxyýỳỷỹỵz';
my $cnt = 0;
$order{$_} = ++$cnt for split //, $source;
sub vcmp($$) {
my ($a, $b) = @_;
for (0..min(length($a), length($b))) {
my $cmp = ($order{substr $a, $_, 1} // 0)
<=> ($order{ substr $b, $_, 1 } // 0);
return $cmp if $cmp != 0;
}
return length($a) <=> length($b);
}
}
say for sort { vcmp($a, $b) } ('ầm', 'ãm', 'ấm chè', 'ám số');
| [reply] [Watch: Dir/Any] |
say for sort { vcmp($a, $b) } ('ầm', 'ãm', 'ấm chè', 'ám số');
with an array like this:
ỷ : (1) to be fat (said of a pig); (2) to depend on
ỳ : inertia, state of inactivity, stay out, inert, sluggish
ỳ ạch : to toil, labor with difficulty
ỷ eo : reproach someone with something
ỷ lại : to depend, rely on others
ỷ thế : count on one’s power, one’s position, one’s influence
yêu nhau : to love each other, be in love
yêu quí : precious, valuable
read in from a text file using something like
open(IN,"test.txt");
@unsorted=<IN>;
Sorry, I know that's a dumb question, but I keep getting errors saying "Global symbol XYZ requires explicit package name ..." when I try to do this.
Thanks again!
| [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] |