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


In reply to Re: Vietnamese Numbers by Abigail-II
in thread Vietnamese Numbers by Cody Pendant

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.