in reply to Re^3: Listing out the characters included in a character class [wide character warning]
in thread Listing out the characters included in a character class

"Wide character in ..." is a warning. See "perldiag: Wide character in %s". Please stop calling it an error.

You showed this warning when using Test::More:

Wide character in print at /.../Test2/Formatter/TAP.pm line 125.

I simulated that warning when using Test::More:

Wide character in print at /.../Test2/Formatter/TAP.pm line 156.

The only difference being the line number which I'd guess, in the absence of other information, is due to you using a different version. Test::More and Test2::Formatter::TAP (along with many other modules) are part of the Test-Simple distribution. I'm using:

$ perl -E 'use Test::More; say $Test::More::VERSION;' 1.302195 $ perl -E 'use Test2::Formatter::TAP; say $Test2::Formatter::TAP::VERS +ION;' 1.302195

What version are you using?

My line 156 looks like this:

print $io $ok;

What does your line 125 look like?

I provided you with a solution to your problem by using:

use open OUT => qw{:encoding(UTF-8) :std};

Did you try that? If so, what was the outcome? If not, why not?

The issue here is in no way specific to Test::More. Consider this code which generates the warning:

$ perl -e '
    print "\N{DROMEDARY CAMEL}\n";
'
Wide character in print at -e line 2.
🐪

And this code which does not:

$ perl -e '
    use open OUT => qw{:encoding(UTF-8) :std};
    print "\N{DROMEDARY CAMEL}\n";
'
🐪

— Ken

  • Comment on Re^4: Listing out the characters included in a character class [wide character warning]
  • Select or Download Code

Replies are listed 'Best First'.
Re^5: Listing out the characters included in a character class [wide character warning]
by choroba (Cardinal) on Nov 03, 2023 at 10:10 UTC
    Note that ordering is important:
    #!/usr/bin/perl
    use warnings;
    use strict;
    use utf8;
    
    use Test::More tests => 1;
    use open OUT => ':encoding(UTF-8)', ':std';
    
    is "kůň", 1, 'same';
    
    gives the warning, while
    #!/usr/bin/perl
    use warnings;
    use strict;
    use utf8;
    
    use open OUT => ':encoding(UTF-8)', ':std';
    use Test::More tests => 1;
    
    is "kůň", 1, 'same';
    
    does not.

    That's why I recommended Test::More::UTF8. You can place it wherever you like and there are no warnings.

    Update: <code> to <pre> to fix the non-English characters.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      ++ Good to know. Thanks.

      Except when turning lexical pragmata on and off in limited scope, I always list pragmatic modules before non-pragmatic ones; so I never would have encountered that situation.

      — Ken

      I didn't realize that with the "use" pragma it would matter the order. I have sometimes even ordered all of them at the top of the script by alphabetic order. I was aware that the "require" usage could be sensitive to order of appearance. Always more to learn, thank you. I wonder how many times in the past this may have bitten me, with me oblivious to the cause.

      Blessings,

      ~Polyglot~

Re^5: Listing out the characters included in a character class [wide character warning]
by Polyglot (Chaplain) on Nov 04, 2023 at 11:55 UTC
    Did you try that? If so, what was the outcome? If not, why not?

    Yes, I copied that into my code, replacing what I was doing (TMTOWTDI) and it made no difference. I had been using these lines already:

    binmode STDERR, ":utf8"; binmode STDIN, ":utf8"; binmode STDOUT, ":utf8";

    Honestly, there are so many ways in Perl of dealing with UTF8 that the mind spins--and they are not all created equal. I had not seen the particular method you recommended, but again, it turned out no different than what I had had in place already. If it does the same as the three lines, I may prefer it going forward. The three-line version does appear to have the advantage of being more specific, giving one the option of selecting among the three options. And I've, at various times, used other methods as well, including the Encode module, etc.

    What does your line 125 look like?

    print $io $msg;
    ...and my line 156 looks identical to yours.

    Regarding the last portion of your post, I know you are well-meaning so I will overlook how it comes across. My username is not without significance. From the very beginning of my Perl programming career, I have dealt with non-ASCII encodings (I was programming for Asian languages from the get-go). The "wide character" message is one I have seen thousands of times--and I well know its typical causes.

    Thank you for your help! (This is genuine, not being sarcastic--I just felt it necessary to clarify owing to the prior paragraph which might color the perception of my tone.)

    Blessings,

    ~Polyglot~