ablegrape has asked for the wisdom of the Perl Monks concerning the following question:
Silly me, I upgraded my development Mac to Snow Leopard, and a bunch of my UTF-8 code broke with the newer version of Perl (5.10.0). I've isolated the problem to a strange behavior with regular expressions, have RT'ed the FM, and can't find an explanation in any of the expected behaviors of newer Perl. Thinking this might be a bug, I've rolled forward to 5.12.0/1, but the problem persists. I could try to roll back to the older (5.6?) Perl, but would prefer to understand what's going on, and fix my code, if possible.
Here's a simple test case. The string in question is valid UTF-8 as far as I can tell (same problem persists when reading from a UTF-8 file), and works with most regular expressions, just not a very specific combination of them.
The program dies thus:#!/usr/bin/perl use strict vars; use utf8; use encoding 'utf8'; my $e = "Böck"; if (utf8::is_utf8($e)) { print "yep, is UTF8\n"; } # this fails with: Malformed UTF-8 character # seems to require the combination of a minimum-length wildcard match # + non-matching character class. For example: # m/.*?[k]$/ succeeds # m/.*?x$/ succeeds # m/.*[x]$/ succeeds if ($e=~ m/.*?[x]$/) { print "matched\n"; } print "success with $e\n";
% ./test.pl yep, is UTF8 Malformed UTF-8 character (fatal) at ./test.pl line 17.
Have tried lots of things, to no avail. Perhaps some monk more adept than I will have a clue as to how to approach this?
Many thanks!
|
|---|