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

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

Replies are listed 'Best First'.
Re^4: How to convert this to swedish characters?
by almut (Canon) on Feb 08, 2007 at 14:00 UTC

    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-ö.
Re^4: How to convert this to swedish characters?
by varian (Chaplain) on Feb 08, 2007 at 14:18 UTC
    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.

Re^4: How to convert this to swedish characters?
by almut (Canon) on Feb 08, 2007 at 14:45 UTC
    ... 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.

        Don't think that would help... :)   For example, printf "%s ", chr($_) for (0x61..0xf6); would already output those characters sorted in hexadecimal order, however, that's not the swedish alphabet...

        Theoretically, you could do print "$_ " for ("a".."z","å","ä","ö"); to print out the swedish alphabet (I don't know a lot about Swedish - that's the alphabet Wikipedia told me) - though I'm not really sure what that would gain you ;)

        Printing out your keymap is an entirely different thing (i.e. displaying all characters that you would get if you pressed all keys on your keyboard, or something like this). Is that what you'd like to do?   In that case you'd have to parse the corresponding keymap files (either the X11 ones , or those belonging to the linux console)... Especially with the X11 keymap structure (multiple files including one another), this might turn out to be a non-trivial task, probably better left to those dedicated tools that come with the xkb X11 extension...