in reply to UTF-8 lexicographic string sort
To implement "UTF-8 lexicographic sorting", you merely have to read in the filenames as UTF-8 (or, when reading them from the filesystem via File::Find, use Encode::decode to convert them to Unicode). Note that the filesystem APIs don't know about UTF-8 or any filename encodings, so you will have to encode the filenames appropriately when talking to the filesystem. Perl will do the rest when you sort them. For example, the following code should do what you describe:
use strict; use warnings; use File::Find; use Encode 'decode'; my @found_files; File::Find::find(sub { push @found_files, decode('UTF-8', $File::Find::name); }, '.'); @found_files = sort @found_files; for my $file (@found_files) { my $fs_name = encode('UTF-8', $file); open my $fh, '<', $fs_name or die "Couldn't open '$file': $!"; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: UTF-8 lexicographic string sort
by rdiez (Acolyte) on Apr 23, 2020 at 12:02 UTC | |
by Corion (Patriarch) on Apr 23, 2020 at 12:08 UTC | |
by rdiez (Acolyte) on Apr 23, 2020 at 14:15 UTC | |
by Corion (Patriarch) on Apr 23, 2020 at 14:22 UTC | |
by haukex (Archbishop) on Apr 23, 2020 at 15:28 UTC |