use warnings;
use 5.016;
use utf8;
use open qw/:std :utf8/;
use Text::CSV qw/csv/; # also install Text::CSV_XS for speed
use Unicode::Collate;
my $Collator = Unicode::Collate->new(
preprocess => sub { $_[0][0] =~ s/^(?:o|a)\s+//ir } );
my $rows = csv( in=>*DATA, sep=>"|", esc=>"\\", auto_diag=>2 );
my @sorted = $Collator->sort(@$rows);
csv( in=>\@sorted,out=>*STDOUT, sep=>"|", esc=>"\\", quote_space=>0 );
__DATA__
a cerveja|beer
o ano|year
a laranja|orange
beber|to drink
įgua|water
o copo de vinho|glass of wine
o copo|glass or cup
o sumo|juice
Output:
įgua|water
o ano|year
beber|to drink
a cerveja|beer
o copo|glass or cup
o copo de vinho|glass of wine
a laranja|orange
o sumo|juice
Update: Realized I could use $Collator->sort instead of $Collator->cmp. |