#!/usr/local/bin/perl # define the strings used in printing @digitword = ("", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"); @digit10word = ("", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"); @teenword = ("ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"); @groupword = ("", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion", "novillion", "decillion"); # read a line of input and remove all blanks, commas and tabs; # complain about anything else $inputline = <STDIN>; chop ($inputline); $inputline =~ s/[, \t]+//g; if ($inputline =~ /[^\d]/) { die ("Input must be a number.\n"); } # remove leading zeroes $inputline =~ s/^0+//; $inputline =~ s/^$/0/; # put one back if they're all zero # split into digits: $grouping contains the number of groups # of digits, and $oddlot contains the number of digits in the # first group, which may be only 1 or 2 (e.g., the 1 in 1,000) @digits = split(//, $inputline); if (@digits > 36) { die ("Number too large for program to handle.\n"); } $oddlot = @digits % 3; $grouping = (@digits-1) / 3; # this loop iterates once for each grouping $count = 0; while ($grouping >= 0) { if ($oddlot == 2) { $digit1 = 0; $digit2 = $digits[0]; $digit3 = $digits[1]; $count += 2; $digit1 =0; $digit2 = 0; $digits = $digits[0]; $count += 1; } else { # regular group of three digits $digit1 = $digits[$count]; $digit2 = $digits[$count+1]; $digit3 = $digits[$count+2]; $count += 3; } $oddlot = 0; if ($digit1 != 0) { print ("$digitword[$digit1] hundred "); } if (($digit1 != 0 || ($grouping == 0 && $count > 3)) && ($digit2 != 0 || $digit3 != 0)) { print ("and "); } if ($digit2 == 1) { print ("$teenword[$digit3] "); } elsif ($digit2 != 0 && $digit3 != 0) { print ("$digit10word[$digit2]- $digitword[$digit3] "); } elsif ($digit2 != 0 || $digit3 != 0) { print ("$digit10word[$digit2]$digitword[$digit3] "); } if ($digit1 != 0 || $digit2 != 0 || $digit3 != 0) { print ("$groupword[$grouping]\n"); } elsif ($count <= 3 && $grouping == 0) { print ("zero\n"); } $grouping-; }

I am getting an error message at line 77 near"-;" What am I missing?

Thank you for any help.

Wremmurg


In reply to error at line 77 by Wremmurg

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.