CGI Script
The Towers of Hanoi as a CGI (cgi-bin) Script.
#!/usr/bin/perl -- -*-perl-*-
# The Towers Of Hanoi
# CGI-bin
# Copyright (C) 1998 Amit Singh. All Rights Reserved.
# http://hanoi.kernelthread.com
#
# Tested under Perl 5.005 / Apache 1.3b3
#
$| = 1;
print "Content-type: text/html\n\n";
if (($#ARGV != 0) || (int($ARGV[0]) < 0) || (int($ARGV[0]) > 10)) {
print "<Head><Title>The Towers Of Hanoi: Error</Title></Head>";
print "<Body>";
print "<H1>Illegal or no input</H1><P>";
print "Please give an appropriate numeric argument to the CGI script.<BR>";
print "The number should be between 1 and 10.<BR>";
print "</Body>";
exit;
}
print "<Head><Title>The Towers Of Hanoi</Title></Head>";
print "<Body><H1>Result for $ARGV[0] disks</H1><P>";
print "$ARGV <BR>";
hanoi($ARGV[0], 3, 1, 2);
print "</Body>";
sub
hanoi
{
local($n, $to, $from, $using) = @_;
if ($n > 0) {
hanoi($n-1, $using, $from, $to);
print "<B>move </B>$from<B> --> </B>$to<BR>\n";
hanoi($n-1, $to, $using, $from);
}
}