Hi, Tk appearing in Chinese font spurred a memory of a question that went unanswered on comp.lang.perl.tk. Someone posted the script below, and wanted to know, why the Chinese was displayed properly if read in as variables, but it wouldn't work reading from DATA. If any of you unicode experts know the answer, please enlighten us. The are 2 subs below for testing, comment out "method1" and try "method2" to see the difference.
#!/usr/bin/perl use warnings; use strict; use Tk; my %codes_hash; my $mw = new MainWindow; #works fine when hard coded, but not from DATA #so method1 is good, method2 is'nt working &define_codes_method1; #&define_codes_method2; foreach my $language ( 'English', 'Chinese', 'Japanese', 'Malay' ) { $mw->Label( -text => $language, -font => 'arial 12 bold' )->pack; foreach my $code ( sort keys %codes_hash ) { $mw->Label( -text => "$codes_hash{$code}{$language} ($code)", -font => 'arial 12', )->pack; } $mw->Label( -text => '-' x 30, -font => 'arial 12' )->pack; } $mw->geometry('+100+100'); MainLoop; sub define_codes_method1 { %codes_hash = ( 100 => { English => "Contactor Repair", Chinese => "\x{4FEE}\x{593E}\x{8173}", Japanese => "PB\x{4FEE}\x{7406}", Malay => "Membaiki Contactor", }, 120 => { English => "Change Cleaning Disk", Chinese => "\x{66F4}\x{63DB}\x{786C}\x{789F}", Japanese => "\x{30AF}\x{30EA}\x{30FC}\x{30CB}\x{30F3}\x{30B0}\x{4EA4}\x{63DB}", Malay => "Menukar Cakera Pencuci", }, 130 => { English => "Server/Network Problem", Chinese => "\x{7DB2}\x{8DEF}\x{554F}\x{984C}", Japanese => "\x{30CD}\x{30C3}\x{30C8}\x{30EF}\x{30FC}\x{30AF}\x{306E}\x{30C0}\x{30 +A6}\x{30F3}", Malay => "Masaalah Server/Rangkaian", }, 140 => { English => "Waiting on Support", Chinese => "\x{5F85}\x{4FEE}\x{6A5F}\x{4EBA}\x{54E1}", Japanese => "\x{30B5}\x{30DD}\x{30FC}\x{30C8}\x{5F85}\x{30 +61}", Malay => "Menunggu Sokongan Teknikal", }, ); } sub define_codes_method2 { my $language; while (<DATA>) { chomp; next if !/\S/; if (/^%language=(.*)/) { $language = $1; } else { my ( $code, $descr ) = split /,/; $codes_hash{$code}{$language} = $descr; } } } __DATA__ %language=English 100,"Contactor Repair" 120,"Change Cleaning Disk" 130,"Server/Network Problem" 140,"Waiting on Support" %language=Chinese 100,"\x{4FEE}\x{593E}\x{8173}" 120,"\x{66F4}\x{63DB}\x{786C}\x{789F}" 130,"\x{7DB2}\x{8DEF}\x{554F}\x{984C}" 140,"\x{5F85}\x{4FEE}\x{6A5F}\x{4EBA}\x{54E1}" %language=Japanese 100,"PB\x{4FEE}\x{7406}" 120,"\x{30AF}\x{30EA}\x{30FC}\x{30CB}\x{30F3}\x{30B0}\x{4EA4}\x{63DB}" 130,"\x{30CD}\x{30C3}\x{30C8}\x{30EF}\x{30FC}\x{30AF}\x{306E}\x{30C0}\ +x{30A6}\x{30F3}" 140,"\x{30B5}\x{30DD}\x{30FC}\x{30C8}\x{5F85}\x{3061}" %language=Malay 100,"Membaiki Contactor" 120,"Menukar Cakera Pencuci" 130,"Masaalah Server/Rangkaian" 140,"Menunggu Sokongan Teknikal"

I'm not really a human, but I play one on earth. flash japh

In reply to Tk-reading-chinese-out-of-data by zentara

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.