1N/AI18N::Collate - compare 8-bit scalar data according to the current locale 1N/A setlocale(LC_COLLATE, 'locale-of-your-choice'); 1N/A $s1 = new I18N::Collate "scalar_data_1"; 1N/A $s2 = new I18N::Collate "scalar_data_2"; 1N/A WARNING: starting from the Perl version 5.003_06 1N/A the I18N::Collate interface for comparing 8-bit scalar data 1N/A according to the current locale 1N/A That is, please do not use it anymore for any new applications 1N/A and please migrate the old applications away from it because its 1N/A functionality was integrated into the Perl core language in the 1N/A See the perllocale manual page for further information. 1N/AThis module provides you with objects that will collate 1N/Aaccording to your national character set, provided that the 1N/APOSIX setlocale() function is supported on your system. 1N/AYou can compare $s1 and $s2 above with 1N/Ato extract the data itself, you'll need a dereference: $$s1 1N/AThis module uses POSIX::setlocale(). The basic collation conversion is 1N/Adone by strxfrm() which terminates at NUL characters being a decent C 1N/Aroutine. collate_xfrm() handles embedded NUL characters gracefully. 1N/AThe available locales depend on your operating system; try whether 1N/AC<locale -a> shows them or man pages for "locale" or "nlsinfo" or the 1N/Aare necessarily installed: please consult your operating system's 1N/Adocumentation and possibly your local system administration. The 1N/Alocale names are probably something like C<xx_XX.(ISO)?8859-N> or 1N/AC<xx_XX.(ISO)?8859N>, for example C<fr_CH.ISO8859-1> is the Swiss (CH) 1N/Avariant of French (fr), ISO Latin (8859) 1 (-1) which is the Western 1N/AEuropean character set. 1N/A# Author: Jarkko Hietaniemi <F<jhi@iki.fi>> 1N/A# Helsinki University of Technology, Finland 1N/A# Acks: Guy Decoux <F<decoux@moulon.inra.fr>> understood 1N/A# overloading magic much deeper than I and told 1N/A# how to cut the size of this code by more than half. 1N/A# (my first version did overload all of lt gt eq le ge cmp) 1N/A# Purpose: compare 8-bit scalar data according to the current locale 1N/A# Requirements: Perl5 POSIX::setlocale() and POSIX::strxfrm() 1N/A# Exports: setlocale 1) 1N/A# Overloads: cmp # 3) 1N/A# Usage: use I18N::Collate; 1N/A# setlocale(LC_COLLATE, 'locale-of-your-choice'); # 4) 1N/A# $s1 = new I18N::Collate "scalar_data_1"; 1N/A# $s2 = new I18N::Collate "scalar_data_2"; 1N/A# now you can compare $s1 and $s2: $s1 le $s2 1N/A# to extract the data itself, you need to deref: $$s1 1N/A# 1) this uses POSIX::setlocale 1N/A# 2) the basic collation conversion is done by strxfrm() which 1N/A# terminates at NUL characters being a decent C routine. 1N/A# collate_xfrm handles embedded NUL characters gracefully. 1N/A# 3) due to cmp and overload magic, lt le eq ge gt work also 1N/A# 4) the available locales depend on your operating system; 1N/A# try whether "locale -a" shows them or man pages for 1N/A# "locale" or "nlsinfo" work or the more direct 1N/A# Not all the locales that your vendor supports 1N/A# are necessarily installed: please consult your 1N/A# operating system's documentation. 1N/A# The locale names are probably something like 1N/A# 'xx_XX.(ISO)?8859-N' or 'xx_XX.(ISO)?8859N', 1N/A# for example 'fr_CH.ISO8859-1' is the Swiss (CH) 1N/A# variant of French (fr), ISO Latin (8859) 1 (-1) 1N/A# which is the Western European character set. 1N/A # the current $LOCALE 1N/A unless (
defined $C->{$
LOCALE}->{$s});
# cache when met 1N/A for (
split(/(\
000+)/, $s)) {
1N/A &C($_[
0])
cmp &C($_[
1]);
1N/A1;
# keep require happy