Hello, wise monks. I believe the code below demonstrates a perl bug, but before reporting it as such, I'd like to run it by the perl cognoscenti, and make sure I'm not doing something foolish. I am running perl v5.22.2 on i686-linux.
The bug is a warning perl emits that seems completely inapplicable, A precise interaction of a number of components seems to trigger it; I've not found a way to further pare down the code snippet below and still trigger the bug. In particular:
- it only happens when input comes from a file; I cannot reproduce it by redirecting stdin, using a DATA block, or any other of the usual means of crafting an example that doesn't rely on external files
- the input-file encoding must be specified as iso-8859-1, even if the input file contains only the ASCII subset of this character set
- smartmatch must be activated, even though this code snippet doesn't use it
- the regular expression is not the simplest way to express this particular match, but all its components seem necessary for the bug to show up
Here is my code:
#!/usr/bin/perl
use experimental 'smartmatch';
use open ':encoding(iso-8859-1)';
use POSIX 'locale_h';
use locale ':ctype';
setlocale(LC_CTYPE, 'en_US.iso88591');
open (FILE, '< s2') || die "Cannot open\n";
while (<FILE>) {
chomp;
print "--$_--\n";
print "ends with x and optional y or z\n" if /x(y|z)?$/;
}
close (FILE);
and here is a sample input file (filename "s2" hard-coded in the the perl code) with one line that passes unremarked, and one line that triggers the bug:
flee
flex
When I run the code, I see:
--flee--
--flex--
Wide character (U+FFFD) in pattern match (m//) at ./fmin line 14, <FIL
+E> line 2.
ends with x and optional y or z
The reported U+FFFD, of course, appears nowhere in the perl code or the input file, so I don't know where it's coming from, hence why I'm pretty sure it's a perl bug rather than something I'm doing wrong. Any insight appreciated!
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.