Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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

Comment on Re: s/.// increases length - bug or badly documented feature
Download Code

Log In?

What's my password?
Create A New User
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 chilling in the Monastery: (8)
As of 2015-07-29 04:49 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (260 votes), past polls