http://qs321.pair.com?node_id=148523


in reply to s/.// increases length - bug or badly documented feature

I think this is a bug. But it is a documented bug. From the documentation on perlunicode (emphasis added by me):

The following areas need further work. They are being rapidly addressed in the 5.7.x development branch.
...
Regular Expressions
The existing regular expression compiler does not produce polymorphic opcodes. This means that the determination on whether to match Unicode characters is made when the pattern is compiled, based on whether the pattern contains Unicode characters, and not when the matching happens at run time. This needs to be changed to adaptively match Unicode if the string to be matched is Unicode.

To see this, I put in a unicode character in a position guaranteed not to match:

#!/usr/bin/perl -l $_ = chr(12345); print "Length: ", length; # Length: 1 s/.|[^$_]//; print "Length: ", length; # Length: 2 # prints: # Length: 1 # Length: 0

Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com