I have some strange result in my script, where I am using Russian characters from UTF-8. If I do it this way, it works:

#!/usr/bin/perl use strict; use warnings; my (@kmap, @rmap, %map); { no warnings; # Не хуя в +опить @kmap = qw/A B V G D E + J Z I Y K L M N O P R S T U F H C X ! @ # + $ % ^ & * a b v g d e = j z i y k l m n o p r s t u f h c x 1 2 3 4 +5 6 7 8/; @rmap = qw/А Б В Г Д Е &#1025 +; Ж З И Й К Л М Н &#1 +054; П Р С Т У Ф Х Ц +Ч Ш Щ Ъ Ы Ь Э Ю &#107 +1; а б в г д е ё ж &# +1079; и й к л м н о п + р с т у ф х ц ч &#10 +96; щ ъ ы ь э ю я/; } @map{@kmap} = @rmap; my $c; for (@kmap){ print "$_: $map{$_}\t"; print "\n" unless ++$c % 9; }

Output:

A: А B: Б V: В G: Г D: Д +E: Е +: Ё J: Ж Z: З I: И Y: Й K: К L: Л M: М +N: Н O: О P: П R: Р S: С T: Т U: У F: Ф H: Х +C: Ц X: Ч !: Ш @: Щ #: Ъ $: Ы %: Ь ^: Э &: Ю +*: Я a: а b: б v: в g: г d: д e: е =: ё j: ж +z: з i: и y: й k: к l: л m: м n: н o: о p: п +r: р s: с t: т u: у f: ф h: х c: ц x: ч 1: ш +2: щ 3: ъ 4: ы 5: ь 6: э 7: ю 8: я

But, if I do it this way:

#!/usr/bin/perl use strict; use warnings; my (@kmap, @rmap, %map); { no warnings; # Не хуя в +опить @kmap = split //, 'ABVGDE+JZIYKLMNOPRSTUFHCX!@#$%^&*abvgde=jziyklm +noprstufhcx12345678'; @rmap = split //, 'АБВГДЕ&#102 +5;ЖЗИЙКЛМНО&#10 +55;РСТУФХЦЧШ&#1 +065;ЪЫЬЭЮЯабв&# +1075;деёжзийкл& +#1084;нопрстуфх +цчшщъыьэю&#1103 +;'; } @map{@kmap} = @rmap; my $c; for (@kmap){ print "$_: $map{$_}\t"; print "\n" unless ++$c % 9; }

then the output looks like this:

A: �B: � V: �G: � D: �E: &#65 +533; +: �J: � Z: � I: � Y: �K: � L: �M: � + N: �O: � P: �R: � S: �T: � U: �F: � H: �C: &#65 +533; X: �!: � @: � #: � $: �%: � ^: �&: � + *: �a: � b: �v: � g: �d: � e: �=: � j: �z: &#65 +533; i: �y: � k: � l: � m: �n: � o: �p: � + r: �s: � t: �u: � f: �h: � c: �x: � 1: �2: &#65 +533; 3: �4: � 5: � 6: � 7: �8: �

Why the difference?

(I see from preview that it is not showing the characters. The first output is English and Russian mapping; the second is English and question marks in ovals instead of Russian letters, and the output is not well aligned.)


In reply to Different behaviour in characters in string vs. array? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.