Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Problem with escape sequence \x for hex with spaces "\x{ 263A }"

by kcott (Archbishop)
on Jun 11, 2022 at 06:10 UTC ( [id://11144684]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Problem with escape sequence \x for hex with spaces "\x{ 263A }"
in thread Problem with escape sequence \x for hex with spaces "\x{ 263A }"

"I think if you want to change STDOUT globally for the debugger, some of the unicode flags in perlrun should do. (untested)"

I tried all of these:

$ perl -C -de1 ... $ perl -de1 ... DB<1> use open OUT => qw{:encoding(UTF-8) :std} ... $ perl -Mopen=OUT,:encoding\(UTF-8\),:std -de1 ...

All gave the "Wide character ..." warning. All still printed "". There's probably other avenues of investigation for a global change: I didn't try anything further.

— Ken

Replies are listed 'Best First'.
Re^4: Problem with escape sequence \x for hex with spaces "\x{ 263A }" (update: codepage)
by LanX (Saint) on Jun 11, 2022 at 10:37 UTC
    I think you need to append 'O' for "Output" to the '-C'

    (my CMD-terminal has CP 850 so no emojis, sorry °)

    C:\tmp>perl -we" binmode STDOUT, ':utf8'; print qq[\x{263A}] " Ôÿ&#9553; C:\tmp>perl -CO -wde0 ... main::(-e:1): 0 DB<1> print "\x{263A}" Ôÿ&#9553; DB<2>

    UPDATE (codepage)

    °) ah found the way to change the codepage

    C:\tmp>CHCP 65001 Aktive Codepage: 65001. C:\tmp>perl -CO -wde0 ... yadda yadda ... DB<1> print "\x{263A}" &#9786; DB<2>

    PM's codeblocks are limited here², thats what I see ---> ☺ (sic)

    update (pre tags)

    ²) or with <pre><tt> tags instead

    
    C:\tmp>perl -CO -wde0
    
    ...
    
      DB<1> print "\x{263A}"
    ☺
      DB<2>
    

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      I don't use the debugger (except in exercises like this) so it's more trial and error than knowledge for me. Anyway, I found the issue actually revolves around whether p or print is used.

      $ perl -C -de1
      ...
        DB<1> print "\x{263A}"
      ☺
        DB<2> p "\x{263A}"
      Wide character ...
      ...
      ☺
      

      My guesswork here was based on a long-standing alias of mine:

      $ alias perlu alias perlu='perl -Mstrict -Mwarnings -Mautodie=:all -Mutf8 -C -E'

      For example:

      $ perlu 'say for $], "\x{263A}", "\x{ 263A }"'
      5.036000
      ☺
      ☺
      

      Update (checking for false positives):

      $ perl -de1
      ...
        DB<1> print "\x{263A}"
      Wide character ...
      ...
      ☺
      
      $ alias perle alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -MCarp::Always -E +'
      $ perle 'say for $], "\x{263A}", "\x{ 263A }"'
      5.036000
      Wide character in say at -e line 1.
      ☺
      Wide character in say at -e line 1.
      ☺
      

      — Ken

        > whether p or print is used.

        good and weird catch.

        I can reproduce that with -CO on windows

            
        C:\tmp>perl -CO -de0
        
        ...
        
          DB<1> p "\x{263A}"
        Wide character in print at (eval 15)c:/nonBKU/strawberry-perl-5.32.1.1-64bit-portable/perl/lib/perl5db.pl:738 line 2.
        ...
        
        ☺
          DB<2> print "\x{263A}"
        ☺
          DB<3> q
        

        I know that p is a hardcoded command and the debugger is fiddling with IO to ensure that debugged program and interactions don't mess with each other.

        Still surprising, hope I find time to look into this.

        > I don't use the debugger

        pity, it's pretty close to a REPL, and both python and ruby come with easy REPLs

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

      Worked a treat on Mac.

      ~>perl -CO -wde0
      # ...
      main::(-e:1):	0
        DB<1> print "\x{263A}"
      ☺
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11144684]
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: (6)
As of 2024-03-28 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found