in reply to How to convert this to swedish characters?

On Perlmonks there's an excellent tutorial to learn about unicode, utf-8 in relationship to perl.
  • Comment on Re: How to convert this to swedish characters?

Replies are listed 'Best First'.
Re^2: How to convert this to swedish characters?
by varian (Chaplain) on Feb 08, 2007 at 11:02 UTC
    Also note that the '..' operator does not handle the special character as one might expect.
    Try the below alternative and you will find that it shows just fine:
    #!/usr/bin/perl -w use encoding "utf8"; use strict; my $start=ord("a"); my $finish=ord("ö"); # use ord value to properly fill the list my @a=($start..$finish); for (@a ) { print chr($_)," $_\n"; } # show that list construct works fine without '..' @a=("a","ö"); print "$_\n" foreach (@a);
      Thank You for your fast reply, but it didn't work. Error:
      Malformed UTF-8 character (1 byte, need 4, after start byte 0xf6) at . +/tryitut line 7. Tried also with use encoding "iso-8859-1"; It made my question more clear to me That worked, but I don't want anything else than the swedish alphabet +to be printed on the screen not the number represent a letter or anyt +hing different at all. How can I do that? I have perl version: perl -v This is perl, v5.8.8 built for i486-linux

        You only want use encoding "utf8"; (or use utf8; for that matter) if your script is encoded in UTF-8 (the latter is one of the possible encodings for unicode). Apparently, your script is not in UTF-8, as 0xf6 for sure is the latin1 encoding of the character "ö". varian's suggestion should work if you simply remove the use encoding "utf8" (latin1 is the default encoding).

        The example code works fine using my Perl release:
        This is perl, v5.8.5 built for i386-linux-thread-multi

        However tricky character set conversions can take place as you download/cut/past program code from the web.
        To rule this out you may want to edit the program to first remove and then type in the special characters locally, see if that helps.

        Or try to change '..' to a comma in the list assignment in your original program.

        ... don't want anything else than the swedish alphabet ...

        As varian noted, the range operator generally does not work with non-ASCII characters. Even if it did work, "a".."ö" would not represent the swedish alphabet, as latin1/iso-8859-1 is a super-set of all characters commonly used in "western european" languages. IOW, what you'd get would simply be all latin1 characters from code 0x61 ("a") to 0xf6 ("ö").