my @units
my @teens
my @tens
####
my %number = (
0 => zero, 1 => one, 2 => two, 3 => three, 4 => four, 5 => five, 6 => six, 7 => seven, 8 => eight, 9 => nine, 10 => ten, 11 => eleven, 12 => twelve, 13 => thirteen, 14 => fourteen, 15 => fifteen, 16 => sixteen, 17 => seventeen, 18 => eighteen, 19 => nineteen, 20 => twenty, 30 => thirty, 40 => forty, 50 => fifty, 60 => sixty, 70 => seventy, 80 => eighty, 90 => ninety);
####
if $number is a key in the hash, print its value, end of the history
else you need to reduce the problem
while $number is not undef
extract the last number of the chain with pop
if the popped number = 0 forget this number
else my $units = this number
pop again
if you have a zero: good bye zero!
else my $teen = this number *10
pop again
if you have a zero: good bye zero!
else my $hundred = this number
my $thereis_a_hundred = true;
... etc, etc ...
pop again ... oups, nothing left to pop, we obtain undef and exit the loop,
my $googolplex = ''; # this variable was not reached, its value is still the null string, so if you print it nothing occurs
}
## print all variables you have collected in reversed position and add some extra strings
## first whe prepare the extra chains, this could be done before also
if ($there_is_hundred is true){my $hundred_str = "hundred and "}
else {$hundred_str = ''};
if ($there_is_thousand is true){my $thousand_string = " thousand, "}
else {$thousand_string = ''};
# ... etc
# we finish
print ....... %number[$thousand] $thousand_string %number[$hundred] $hundred_str %number[$teen], %number[$unit];
# and we close all with the required "}"