I am writing a flash card program with PERL, and I have two problems:

How do I read from a file in the format:

[][][] \t pronunciation [][][] \t pronunciation

the [][][] basically represents any number of Unicode characters [in my case, Chinese], and the pronunciation is in regular test.

and secondly, how do I ensure that Unicode will work on this program:

open(INPUT,"<","c:\\software\\alexcode\\AlexData.txt") or die"Could not open input file for reading\n"; $count = 0; my @prehasha = (); while (<INPUT>) { chomp; my ($values1, $values2) = split(/\t/,$_); $prehasha[$count++] = $values1; $prehasha[$count++] = $values2; print "$values1 and $values2\n"; } #above this Mike wrote print "after while statement @prehasha \n"; #now we have an array where the first element is the char and the seco +nd element is the pinyin etc. @char = (); @pinyin = (); while (@prehasha != 0) { $a = shift @prehasha; $b = shift @prehasha; push (@char, $a); push (@pinyin, $b); #the array has officially been split! } print "@char : @pinyin\n"; keys %charpinyin = @char; #values %charpinyin = @pinyin; #Mike approved 8:44 PM $elnum = ($char)/2; #now is where we assign random numbers to each pair in the hash! $randomarray{$elnum-1} = (); foreach (@randomarray) { push (@random, int( rand($elnum-1) )-1) } #keys %randhash = 1..$elnum-1; #values %randomhash = @randomarray; #now we have two hashes, %charpinyin, and %randomarray, what I will do + now is sort the randomhash hash based on the random number, and use +the key [0..elnum-1] to determine which pair to spit off on the scree +n! clever, eh? #the following few lines is ONLY a test# while (($key, $value) = each(%charpinyin)) { print "$key \t $value \n"; }

20040806 Janitored by Corion: Fixed formatting

janitored by ybiC: Retitle from less-than-descriptive "Trouble", as one-word titles hinder site search


In reply to Reading unicode characters from file 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.