in reply to Perl custom sort for Portuguese Lanaguage
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl custom sort for Portuguese Lanaguage
by ikegami (Patriarch) on Jun 14, 2020 at 00:03 UTC | |
|
Re^2: Perl custom sort for Portuguese Lanaguage
by Galdor (Sexton) on Jul 08, 2020 at 06:03 UTC | |
by haukex (Archbishop) on Jul 08, 2020 at 06:07 UTC | |
by Galdor (Sexton) on Jul 08, 2020 at 06:38 UTC | |
by haukex (Archbishop) on Jul 08, 2020 at 18:03 UTC | |
by hippo (Archbishop) on Jul 08, 2020 at 20:04 UTC | |
|