in reply to Re: Unicode input for Win32::Console
in thread Unicode input for Win32::Console

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?

Replies are listed 'Best First'.
Re^3: Unicode input for Win32::Console
by BrowserUk (Patriarch) on Oct 25, 2011 at 17:59 UTC
    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 $!.

        From what I can tell, Win32::Console has never been updated since the advent of the Perl Unicode era, hence it simply isn;t configured to compile such that it will work correctly with Unicode input.

        It seems it should be possible to make the module work, but it looks like there would be a bunch of effort required in tracking down the correct set of incantations for the MS compiler to allow it to do so. Whether that would then be portable to MingW is another question entirely.


        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.