Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: s/.// increases length - bug or badly documented feature

by clemburg (Curate)
on Mar 01, 2002 at 09:39 UTC ( #148523=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://148523]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2021-10-22 03:42 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (85 votes). Check out past polls.