in reply to Re^2: Accented characters
in thread Accented characters
I am certainly no expert in Perl internals. In my understanding, perl treats strings as if they are Latin-1 unless it can't (it contains a character that isn't in Latin-1) or you have set a locale or pragma which forces it otherwise.
It can be pretty hard to catch perl at this. One way is to use the bizarre (in my opinion) fact that the perl regex engine will recognize a non-breaking space with a \s assertion if the string is encoded as utf-8 but not if it is encoded as Latin-1. Run the following little script to demonstrate. (You don't want to know how much hair I pulled out before I figured this one out...)
for my $string ( "< Á>", "< Á\x{0100}>" ) { print "Has ", $string =~ /\s/ ? 'a' : 'no', " space.\n"; }
Those strings are "<\x{A0}\x{C1}>" and "<\x{A0}\x{C1}\x{100}>" if they don't show up correctly...
All that being said, your solution is probably better than mine since it makes no assumptions about the encoding of the input string.
|
|---|