Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi, I may be too late, seeing your message has been here since nearly two months, but it could still be of use to you or someone else.

I may be wrong, but it seems to me like the problem does not reside with the whitespaces, but with the definition of word in Perl : \w+ does not match chinese characters.

On my system (with unicode locale and chinese readable in the console) :
$ perl -le 'print "ok" if ("我走" =~ m/\w+/)' $ perl -le 'print "ok" if ("hi" =~ m/\w+/)' ok
(Chinese chars were jumbled, I didn't put the codes in the one-liner)

Furthermore, I played a bit with your code, and when I replaced
$terms =~ s/($word)\p{IsSpace}*($word)/$1 AND $2/g for 1..2;
$terms =~ s/(\p{IsSpace}/ AND /g;
it did the job I expected of it.

The quickest workaround I see at the moment would be to declare $word using CJK character ranges instead of \w.

Hope I could be of help.


In reply to Re^5: Unicode substitution regex conundrum by Lu.
in thread Unicode substitution regex conundrum by Polyglot

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (10)
    As of 2018-03-22 20:29 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (286 votes). Check out past polls.