I'm wondering if this is a bug in 5.8's handling of regex character classes, or whether it's just a case of the "perlre" man page being a bit off... (this applies to 5.8.0 and 5.8.1 equally)
Reading perlre, I would expect the following two regexes to match the same set of characters (in the ASCII range, at least), because they are said to be "equivalent":
/[[:punct:]]/
/\p{IsPunct}/
But when I tried the following little test snippet, I got a bit of a surprise:
for $x ( 0x20 .. 0x7e ) {
$_ = chr( $x );
$res = ( /[[:punct:]]/ ) ? "matches :punct:" : "is not a :punct:"
+;
$res .= ( /\p{IsPunct}/ ) ? " matches {IsPunct}" : " fails on {Is
+Punct}";
printf( " 0x%x (%3d.) %s %s\n", $x, $x, $_, $res ) if ( $res =~ /m
+atches/ );
}
Actually, when I look at the output, there seems to be some rhyme and reason to the discrepancies, so it looks like a "feature" (not a bug) to have the two different notions of "punctuation" (and the docs should be updated accordingly):
- [:punct:] -- the "posix" notion of punctuation -- is basically the same as
[^\x00-\x20\x7f\w] [^0-9A-Za-z\x00-\x20\x7f]
- \p{IsPunct} -- the "unicode" notion of punctuation -- refers to things that users of natural languages normally refer to as "punctuation", meaning things that you see/use in text for grouping or separating words in (usually) meaningful ways. (In this sense, it also extends to things outside the ASCII range.)
I wasn't sure which perl mailing list(s) I would post this to, so I decided to check here first.
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.