in reply to Re: How to convert this to swedish characters?
in thread How to convert this to swedish characters?

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);

Replies are listed 'Best First'.
Re^3: How to convert this to swedish characters?
by learn_perl_se (Initiate) on Feb 08, 2007 at 13:34 UTC
    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).

        Thank You
        I just tried it without that line "use encoding" utf8",but it didn't w +ork, which means that the output was from a-z not from a-ö.
      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 ("ö").

        Ok maybe you could sort them in hexadecimal order to get the proper swedish alphabet? I don't know if it makes any difference.My OS (Slackware) installation is in english,but my keymap is in swedish.But in case it does.