Hello there; I am rather new getting back to Perl, and I needed to do a script that would convert normal numbers to Mayan Base 20 counting symbols. I have the symbols part done, but I was hoping someone could help me put my script code into shape. I'm sure you can thing of some ways to make it faster or smaller or both. I only need to do from 1 to 9999, and I am substituting anything but numbers to //. Any help would be appreciated...
#!/usr/bin/perl print "Content-type: text/html\n\n"; use strict; use POSIX qw( ceil floor ); my $num = 9998; my $string1=''; my $string2=''; my $string3=''; my $string4=''; my $first8 = floor($num/8000); my $a = ($first8*8000); if ($first8 > 0) { $string1 .="1st line has $first8 times 8000 = $a"; } else { $string1 .="1st line has nothing "; } print "$string1 <br>\n"; my $second8= $num - $a; $second8 = floor($second8/400); my $b = ($second8*400); if ($second8 > 0) { my $third8 = $num - $second8 - ($second8*400); $string2 .="2nd line has $second8 times 400 = $b"; } else { $string2 .= "2nd line has nothing"; } print "$string2 <br>\n"; my $third8= $num-$a-$b; $third8 = floor($third8/20); my $c = ($third8*20); if ($third8 > 0) { $string3 .="3rd line has $third8 times 20 = $c"; } else { $string3 .="3rd line has nothing"; } print "$string3 <br>\n"; my $cumulative = $num - $a - $b - $c; if ($cumulative > 1) { $string4.="4th line has 1 times all = $cumulative"; } else { $string4.= "NOTHING LEFT OVER "; } print "$string4<br>\n";

In reply to Base20 Blues by JimDuyer

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.