Hi, I've got some code that I wrote while working on a Windows machine that does not work when used on Linux or MacOS. The key line of the code is this:
print OUT chr(charnames::vianame("$symbolName"));
When I run the program on Windows, the outputted file consists of correct Unicode characters. When I run the same program on Linux or MacOS, the file consists of gobbledy-gook. Whether I run on Windows, Mac, or Linux, the debug statements show the same exact sorts of results (as if it is doing the right thing):
Word is th;n
Writing t as GREEK SMALL LETTER TAU
Writing h; as GREEK SMALL LETTER ETA WITH VARIA
Writing n as GREEK SMALL LETTER NU

I prefer to work on MacOS or Linux rather than Windows so would like to figure out what the problem is. Below is the whole program. Thanks for any help.
use charnames ":full"; binmode(STDOUT, ":utf8"); %mapUnicode = (); open(MAP, "map2.txt") or die "!"; while(<MAP>) { next if (/^#/); next if ($_ !~ /[A-Z]/); chomp; if (length $_ > 0) { my @mapInfo = split / ### /; $mapUnicode{"$mapInfo[0]"} = $mapInfo[2]; } } close(MAP); open IN, "greekwords1.txt" or die "!"; open OUT, ">:utf8", "greekwords2.txt"; $buffer = ""; while(<IN>) { chomp; my $word = $_; print "\nWord is $word\n"; while($word =~ m/(.)/g) { my $newPart = $1; my $prospectiveUnit = "$buffer$newPart"; if (exists $mapUnicode{$prospectiveUnit}) { $buffer = $prospectiveUnit; } else { my $symbolName = $mapUnicode{$buffer}; print "Writing $buffer as $symbolName\n"; print OUT chr(charnames::vianame("$symbolName")); $buffer = "$newPart"; } } my $symbolName = $mapUnicode{$buffer}; print "Writing $buffer as $symbolName\n"; print OUT chr(charnames::vianame("$symbolName")); $buffer = ""; print OUT "\n"; } close IN; close OUT;

In reply to unicode issues on Unix only by csthflk

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.