#!/usr/bin/perl # # To use this script, make sure that allkeys.txt from http://www.unicode.org/Public/UCA/latest/allkeys.txt # is either installed in @INC or in ./Unicode/Collate. This file is not installed by the CPAN package and must be # added afterwards. use strict; use warnings; use Unicode::Collate; use lib '.'; # for allkeys.txt in ./Unicode/Collate use utf8; # Enable Unicode literals in test data # Test data my $hebrew_alef = chr(0x05d0); my $hebrew_bet = chr(0x05d1); my @unsorted = ($hebrew_bet, 'alpha', $hebrew_alef, 'gamma', 'beta'); my @danish_unsorted = qw( Æsop Aarhus Øresund Århus ); binmode(STDOUT,':encoding(UTF-8)'); # Get a (re-usable) collator object my $Collator = Unicode::Collate->new(); # Sort my @sorted = $Collator->sort(@unsorted, @danish_unsorted); my $out = join "\n", @sorted; print ">>> Sorted with Unicode Collation <<<\n"; print "$out\n"; @sorted = sort(@unsorted, @danish_unsorted); $out = join "\n", @sorted; print ">>> Default sorting without Unicode Collation <<<\n"; print "$out\n";