FWIW: Yet another snippet, slightly different approach:
>perl -wMstrict -le "sub T { my $n = 0; $n += $_ for @_; return $n <= 9 ? $n : T(split '', $n); } printf qq{%5s -> %d \n}, $_, T($_) for @ARGV " 1818 1819 1918 1500 5001 51 2300 0230 32 1 9 0 00 00000 10000 00001 1818 -> 9 1819 -> 1 1918 -> 1 1500 -> 6 5001 -> 6 51 -> 6 2300 -> 5 0230 -> 5 32 -> 5 1 -> 1 9 -> 9 0 -> 0 00 -> 0 00000 -> 0 10000 -> 1 00001 -> 1

In reply to Re^2: Question on Recursion by AnomalousMonk
in thread Question on Recursion by prasadbabu

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.