Two days ago, I was having the same issues. My testing script is a bit more elaborate, but confirms your problem:
\w does not work under
use locale, whatever the locale is. If you need locale, use posix classes or unicode character properties (provided your locale is unicode based).
Discussion on the details can be found in
perlunicode and
perllocale, but the relevant paragraphs are quite different in each version of Perl.
#!/usr/bin/perl
use warnings;
use strict;
my @p_locale = qw/C cs_CZ.UTF8 en_US.UTF8/;
my @locale = ('no locale', 'use locale');
my @posix = (q(),
'use POSIX qw/locale_h/; setlocale LC_ALL,"C"',
'use POSIX qw/locale_h/; setlocale LC_ALL,"cs_CZ.UTF8"',
);
for my $p_locale (@p_locale) {
for my $locale (@locale) {
for my $posix (@posix) {
print "$p_locale $locale $posix\n";
open my $OUT, '>', 'l.perl' or die "$!";
print {$OUT} << " OUT";
$locale;
$posix;
my \@chars = qw/283 269 345 225
32
98 99 48 49 50 51 52
32
353 253 382 237/;
my \$string = join q[], map chr, \@chars;
binmode STDOUT, ':utf8';
my \@regex = (qr/(\\w+)/, qr/([[:alnum:]]+)/, qr/(\\p{W
+ord}+)/);
for my \$regex (\@regex) {
print "\t\$1" while \$string =~ /\$regex/g;
print "\n";
}
print sort qw/ci ch/;
print "\n";
OUT
close $OUT;
$ENV{LC_ALL} = $p_locale;
system 'perl', 'l.perl';
}
}
}
unlink 'l.perl';
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.