Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
And now, the re-write:
use strict; use warnings; use CGI qw(header param); use HTML::Template; my @solution; my $tmpl = HTML::Template->new(filehandle => \*DATA); if (param('go')) { my $discs = param('discs'); $discs = 1 if $discs < 1 or $discs > 15; hanoi($discs,'A','B','C'); $tmpl->param( solution => \@solution, discs => $discs, ); } print header, $tmpl->output; # original algorithm learned from Brenda Parker sub hanoi { my ($number, $from, $to, $aux) = @_; if ($number == 1) { push @solution, {step => "Move 1 from $from to $to"}; } elsif ($number != 0) { hanoi($number-1,$from,$aux,$to); push @solution, {step => "Move $number from $from to $to"}; hanoi($number-1,$aux,$to,$from); } } __DATA__ <html> <head> <title>Towers of Hanoi</title> </head> <body> <form> <p> Enter number of discs desired (15 is MAX): <input type="text" name="discs" size="2" /> </p> <input type="submit" name="go" value="Solve" /> </form> <tmpl_if solution> <hr/> Solving for <tmpl_var discs> discs: <ol> <tmpl_loop solution> <li><tmpl_var step></li> </tmpl_loop> </ol> </tmpl_if> </body> </html>

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to 2Re: Worst thing you ever made with Perl by jeffa
in thread Worst thing you ever made with Perl by Juerd

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (3)
    As of 2014-07-26 10:29 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (175 votes), past polls