Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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>


(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

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, 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
  • 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (5)
    As of 2021-03-01 04:05 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found