Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Can I change \s?

by ikegami (Patriarch)
on Oct 28, 2011 at 21:57 UTC ( [id://934524]=note: print w/replies, xml ) Need Help??


in reply to Can I change \s?

\s is suppose to match U+00A0 and sometimes does. It's a bug in Perl that cannot be fixed for backwards compatibility reasons. You can indicate you want the fix using feature unicode_strings. In earlier versions of Perl, you can also work around the bug by upgrading the string's internal format.

use strict; use warnings; use feature qw( say ); my $string = chr(160); no feature qw( unicode_strings ); say $string =~ /^\s*$/ ? 1 : 0 ; # 0 use feature qw( unicode_strings ); say $string =~ /^\s*$/ ? 1 : 0; # 1 no feature qw( unicode_strings ); utf8::upgrade($string); say $string =~ /^\s*$/ ? 1 : 0; # 1

Replies are listed 'Best First'.
Re^2: Can I change \s?
by JavaFan (Canon) on Oct 28, 2011 at 23:17 UTC
    Note that the feature unicode_strings was introduced in 5.12, but to make \s match \xA0 on a non-utf-8 strings, you need 5.14:
    $ perl-5.14.2 -wE '$_ = chr 0xA0; say /\s/ || 0' 1 $ perl-5.12.2 -wE '$_ = chr 0xA0; say /\s/ || 0' 0
    The -E enables "use feature 'unicode_strings'".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found