in reply to Re^2: perl 5.14 regex: case insensitive match on international characters
in thread perl 5.14 regex: case insensitive match on international characters

As well as use utf8 make sure your script is actually saved as UTF8. (Your editor will probably offer a choice of encodings upon saving the file.)

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
  • Comment on Re^3: perl 5.14 regex: case insensitive match on international characters
  • Download Code

Replies are listed 'Best First'.
Re^4: perl 5.14 regex: case insensitive match on international characters
by shamat (Acolyte) on Mar 16, 2012 at 09:09 UTC
    Thank you so much! Everything works fine now. Yepeeeee :)
Re^4: perl 5.14 regex: case insensitive match on international characters
by shamat (Acolyte) on Mar 16, 2012 at 17:15 UTC
    Hi monks. Sorry to bother again, but anytime I try to print a double quoted string, I get this "Wide character in print" message. For instance:
    use utf8; use feature 'unicode_strings'; my $string1 = "ŠIN"; my $string2 = "šin"; print "$string1 matches $string2 ? "; print $string1 =~ /$string2/i ? 'matched' : 'no match';
    The result is correct though: ŠIN matches šin ? matcheded. Do you know why perl is assuming that wide character are in print? This in fact causes me troubles with regular expressions somwhere elese in the code: I believe that š and Š are "seen as" (sorry for the horrible terminology) �, and that is why they match in the code above. Thanks for the help!

      When you open a filehandle, if you want to print non-ASCII characters to it, you must specify an encoding. STDOUT is a filehandle. Add something like this near the top of your script:

      binmode(STDOUT, ":utf8");

      If you expect to read from STDIN, then you might want to call binmode on that too.

      There's utf8::all which takes care of a lot of these gotchas.

      If everyone used UTF-8 for everything, and assumed that everybody else did too, then life would be much easier.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
        Thank you so much Tobyink! utf8::all is what I was looking for :)