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

Re: Unicode input for Win32::Console

by BrowserUk (Patriarch)
on Oct 24, 2011 at 21:11 UTC ( [id://933477]=note: print w/replies, xml ) Need Help??


in reply to Unicode input for Win32::Console

You will need to use the high-level InputChar() rather than the low-level Input(). And you will almost certainly need to set the consoles input code-page (try 65001).


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Unicode input for Win32::Console
by Sue D. Nymme (Monk) on Oct 25, 2011 at 17:26 UTC

    Hi BrowserUK. Thanks for your reply. I tried your suggestion. Here is a new test program:

    use Win32::Console; my $wc = Win32::Console->new(STD_INPUT_HANDLE); $wc->InputCP(65001); say 'Paste stuff now.'; Char: while (1) { my $char = $wc->InputChar(1); if (!defined $char) { say 'Read (undef)'; next Char; } # "pretty" character, for display my $pch = $char =~ /[[:^print:]]/? '?' : $char; # Deconstruct the character my @c = unpack 'C*', $char; say "Read: '$pch' = ", join ' - ', map sprintf('%02X',$_), @c; last if $char eq "\n"; }

    It didn't work. InputChar returns undef when I paste a unicode character. Here's the output of the program when I pasted "# “dog’s” leg":

    Read: '#' = 23 Read: ' ' = 20 Read (undef) Read: 'd' = 64 Read: 'o' = 6F Read: 'g' = 67 Read (undef) Read: 's' = 73 Read (undef) Read: ' ' = 20 Read: 'l' = 6C Read: 'e' = 65 Read: 'g' = 67 Read: '?' = 0D Read: '?' = 0A

    The doco for InputChar says that it returns undef "on errors". But the module doesn't provide an interface to the Windows Console LastError function, so I can't see how to tell what error occurred.

    Any suggestions?

      But the module doesn't provide an interface to the Windows Console LastError function, so I can't see how to tell what error occurred.

      Use the Perl built-in $^E to display the windows error code or text.

      I'll try to take a look at this later.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        $^E seems never to be changed by Win32::Console::InputChar. When I add $^E (or $!) to the "(undef)" display in my code above, it always contains the last error before the loop began. I can force it to be any value, and when InputChar returns undef, it does not set $^E or $!.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-25 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found