Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by clemburg (Curate)
on Mar 01, 2002 at 09:39 UTC ( [id://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
http://www.brainbench.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 03:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found