in reply to Vietnamese Numbers

It isn't clear from your description what the vietnamese for '110' is. Should it be 'mot tram mot muoi', or 'mot tram muoi'? If it's the former, the following fix will work:
use strict; use warnings 'all'; my %numbers = ( 0, '', 1, 'mot', 2, 'hai', 3, 'ba', 4, 'bon', 5, 'nam', 6, 'sau', 7, 'bay', 8, 'tam', 9, 'chin', 10, 'muoi', 100, 'tram', 1000, 'ngan' ); sub translate { my $number = $_[0]; my @output = (); if (defined($numbers{$number})) { my $text_version = $numbers{$number}; print "$text_version \n"; } else { my $reverse_number = reverse($number); my $places = 1; my @digits = split ('', $reverse_number); foreach my $digit (@digits) { next unless $digit; if ($places == 1) { push (@output, $numbers{$digit}); } else { push (@output, $numbers{$places}); unless ($number < 20) { push (@output, $numbers{$digit}); } } } continue { $places *= 10; } @output = reverse(@output); print "@output \n"; } }
You were having a problem for dealing with the digit '0'. You were parsing '101' as '1 times 100, 0 times 10, and 1', and the '0 times 10' was emitted as "vietnamese for zero" followed by "vietnamese for ten", resulting in "muoi".

Abigail

Replies are listed 'Best First'.
Re: Re: Vietnamese Numbers
by Cody Pendant (Prior) on Aug 01, 2002 at 23:42 UTC
    Thank you both very much for your help. It's all working fine now.

    For the record, those aren't the actual correct numbers as written -- Vietnamese has so many diacritical marks, often two to a vowel, that you have to download special fonts and keyboard layouts.

    It's hard to program in Perl when the "{" comes out "À"
    --

    ($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;