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.

#!/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";
The program dies thus:
% ./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!


In reply to Odd problems with UTF-8, regexps, and newer Perl versions by ablegrape

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.