Front page | perl.beginners |
Postings from April 2003
Re: multiple sorts
Thread Previous
|
Thread Next
From:
Kevin Pfeiffer
Date:
April 30, 2003 07:42
Subject:
Re: multiple sorts
Message ID:
5976875.OmPr4LEobY@sputnik.tiros.net
In article <3EAFA878.DE6AC17F@acm.org>, John W. Krahn wrote:
> You have to use the locale pragma for locales to work.
>
> # set the locale to whatever
>
> [some code that doesn't need locale]
>
> use locale; # turn locale usage ON
>
> [some code that uses the locale]
>
> no locale; # turn locale usage OFF
I was (but forgot to include it here). Here is my test script which I just
looked at again (and which I still can't get to DWIM):
#!/usr/bin/perl -w
use strict;
use locale;
# Import locale-handling tool set from POSIX module.
use POSIX qw(locale_h);
#
# query and save the old locale
my $old_locale = setlocale( LC_CTYPE, 'en_US.ISO8859-1' );
my @words = qw( Potato
�pfel
Apple
�zin
Ocean
Paul
apple
zebra
purple
�zim
);
print "Unsorted List:\n";
foreach (@words) {
print;
print "\n";
}
print "\n\n";
print "Sorted List:\n";
my @sorted = sort @words;
foreach (@sorted) {
print;
print "\n";
}
print "\n";
setlocale(LC_CTYPE, "");
# restore the old locale
setlocale(LC_CTYPE, $old_locale);
#####
I get results like:
Unsorted List:
Potato
�pfel
Apple
�zin
Ocean
Paul
apple
zebra
purple
�zim
Sorted List:
Apple
Ocean
Paul
Potato
apple
purple
zebra
�pfel
�zim
�zin
:-(
-K
--
Kevin Pfeiffer
International University Bremen
Thread Previous
|
Thread Next