Loading ...
Sorry, an error occurred while loading the content.

Unicode Output Problem

Expand Messages
  • Mike Frank
    I have been trying to figure out how to convert Unicode into characters in any language in a command window, with little success. Here is the code: use strict;
    Message 1 of 6 , Nov 15, 2010
    • 0 Attachment
      I have been trying to figure out how to convert Unicode into characters in any language in a command window, with little success.

      Here is the code:

      use strict;
      use warnings;
      use utf8;

      my $Tomorrow = "ma\x{c3b1}ana";
      print $Tomorrow;


      and here is the result:

      Wide character in print at utf8Test.pl line 8.
      ma쎱ana

      BTW: Those garbage characters are suppose to be an 'n' with a tilde over it.

      Thanks
    • merlyn@stonehenge.com
      ... Mike use utf8; Mike my $Tomorrow = ma x{c3b1}ana ; Mike print $Tomorrow; ... Mike Wide character in print at utf8Test.pl line 8. Mike ma쎱ana
      Message 2 of 6 , Nov 15, 2010
      • 0 Attachment
        >>>>> "Mike" == Mike Frank <m-frank@...> writes:

        Mike> use utf8;

        Mike> my $Tomorrow = "ma\x{c3b1}ana";
        Mike> print $Tomorrow;

        ...

        Mike> Wide character in print at utf8Test.pl line 8.
        Mike> ma쎱ana

        Yes, by default, stdout is presumed to be 8-bit chars only. You should
        read "perldoc perluniintro" to begin to get your head wrapped around all
        the things you need to do to have wide characters in your processing
        path. Hint: it's not obvious or necessarily easy, but it's necessary.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
        See http://methodsandmessages.posterous.com/ for Smalltalk discussion
      • Mike Frank
        I did do some reading in perldoc perluniintro and I never got an answer to my question about printing the actual Unicode character from the Unicode. The
        Message 3 of 6 , Nov 15, 2010
        • 0 Attachment
          I did do some reading in "perldoc perluniintro" and I never got an answer to my question about printing the actual Unicode character from the Unicode. The only thing I was able to accomplish was the elimination of "wide character"; it did not print the character (which is what I wanted it to do).

          Any other suggestions?

          -----Original Message-----
          From: Randal L. Schwartz [mailto:merlyn@...]
          Sent: Monday, November 15, 2010 10:28 AM
          To: Mike Frank
          Cc: perl-beginner@yahoogroups.com
          Subject: Re: [PBML] Unicode Output Problem

          >>>>> "Mike" == Mike Frank <m-frank@...> writes:

          Mike> use utf8;

          Mike> my $Tomorrow = "ma\x{c3b1}ana";
          Mike> print $Tomorrow;

          ...

          Mike> Wide character in print at utf8Test.pl line 8.
          Mike> ma쎱ana

          Yes, by default, stdout is presumed to be 8-bit chars only. You should
          read "perldoc perluniintro" to begin to get your head wrapped around all
          the things you need to do to have wide characters in your processing
          path. Hint: it's not obvious or necessarily easy, but it's necessary.

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
          See http://methodsandmessages.posterous.com/ for Smalltalk discussion
        • merlyn@stonehenge.com
          ... Mike I did do some reading in perldoc perluniintro and I never got an Mike answer to my question about printing the actual Unicode character Mike from
          Message 4 of 6 , Nov 15, 2010
          • 0 Attachment
            >>>>> "Mike" == Mike Frank <m-frank@...> writes:

            Mike> I did do some reading in "perldoc perluniintro" and I never got an
            Mike> answer to my question about printing the actual Unicode character
            Mike> from the Unicode. The only thing I was able to accomplish was the
            Mike> elimination of "wide character"; it did not print the character
            Mike> (which is what I wanted it to do).

            Show what you tried. How did you change the code you just posted?

            And keep in mind, the path from the stdout to your terminal must also
            understand unicode.

            That's the problem with unicode... lots of moving parts.

            --
            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
            See http://methodsandmessages.posterous.com/ for Smalltalk discussion
          • Mike Frank
            This is what I tried. use strict; use warnings; #use utf8; use Encode; my $Tomorrow = ma x{c3b1}ana ; my $temp_Tomorrow=decode_utf8($Tomorrow); print n
            Message 5 of 6 , Nov 15, 2010
            • 0 Attachment
              This is what I tried.



              use strict;
              use warnings;
              #use utf8;
              use Encode;

              my $Tomorrow = "ma\x{c3b1}ana";
              my $temp_Tomorrow=decode_utf8($Tomorrow);
              print "\n $temp_Tomorrow";

              #print $Tomorrow;



              How can I find out if STDOUT understands Unicode?
              Also, does Perl require a package for it to understand Unicode?

              Thanks

              -----Original Message-----
              From: Randal L. Schwartz [mailto:merlyn@...]
              Sent: Monday, November 15, 2010 10:47 AM
              To: Mike Frank
              Cc: perl-beginner@yahoogroups.com
              Subject: Re: [PBML] Unicode Output Problem

              >>>>> "Mike" == Mike Frank <m-frank@...> writes:

              Mike> I did do some reading in "perldoc perluniintro" and I never got an
              Mike> answer to my question about printing the actual Unicode character
              Mike> from the Unicode. The only thing I was able to accomplish was the
              Mike> elimination of "wide character"; it did not print the character
              Mike> (which is what I wanted it to do).

              Show what you tried. How did you change the code you just posted?

              And keep in mind, the path from the stdout to your terminal must also
              understand unicode.

              That's the problem with unicode... lots of moving parts.

              --
              Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
              <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
              Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
              See http://methodsandmessages.posterous.com/ for Smalltalk discussion
            • merlyn@stonehenge.com
              ... Mike This is what I tried. Mike use strict; Mike use warnings; Mike #use utf8; Mike use Encode; Mike my $Tomorrow = ma x{c3b1}ana ; Mike my
              Message 6 of 6 , Nov 15, 2010
              • 0 Attachment
                >>>>> "Mike" == Mike Frank <m-frank@...> writes:

                Mike> This is what I tried.
                Mike> use strict;
                Mike> use warnings;
                Mike> #use utf8;
                Mike> use Encode;

                Mike> my $Tomorrow = "ma\x{c3b1}ana";
                Mike> my $temp_Tomorrow=decode_utf8($Tomorrow);
                Mike> print "\n $temp_Tomorrow";

                Mike> #print $Tomorrow;



                Mike> How can I find out if STDOUT understands Unicode?
                Mike> Also, does Perl require a package for it to understand Unicode?

                You aren't telling Perl that stdout is unicode.

                Please read the rest of perluniintro, especially:

                To output UTF-8, use the ":encoding" or ":utf8" output layer.
                Prepending

                binmode(STDOUT, ":utf8");

                to this sample program ensures that the output is completely UTF-8, and
                removes the program's warning.

                And then eliminate your decode_utf8 call.

                --
                Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                See http://methodsandmessages.posterous.com/ for Smalltalk discussion
              Your message has been successfully submitted and would be delivered to recipients shortly.