rlm@0: #!C:/strawberry/perl/bin/perl.exe
rlm@0: use strict;
rlm@0: use CGI::Ajax;
rlm@0: use CGI;
rlm@0:
rlm@0: # define an anonymous perl subroutine that you want available to
rlm@0: # javascript on the generated web page.
rlm@0:
rlm@0: my $evenodd_func = sub {
rlm@0: my $input = shift;
rlm@0:
rlm@0: my $magic = " look ma, no submit!
";
rlm@0:
rlm@0: # see if input is defined
rlm@0: if ( not defined $input ) {
rlm@0: return("input not defined or NaN" . $magic);
rlm@0: }
rlm@0:
rlm@0: # see if value is a number (*thanks Randall!*)
rlm@0: if ( $input !~ /\A\d+\z/ ) {
rlm@0: return("input is NaN" . $magic);
rlm@0: }
rlm@0:
rlm@0: # got a number, so mod by 2
rlm@0: $input % 2 == 0 ? return("$input is EVEN" . $magic) : return("$input is ODD" . $magic);
rlm@0:
rlm@0: }; # don't forget the trailing ';', since this is an anon subroutine
rlm@0:
rlm@0: # define a function to generate the web page - this can be done
rlm@0: # million different ways, and can also be defined as an anonymous sub.
rlm@0: # The only requirement is that the sub send back the html of the page.
rlm@0: sub Show_HTML {
rlm@0: my $html = "";
rlm@0: $html .= <
rlm@0: CGI::Ajax Example
rlm@0:
rlm@0:
rlm@0:
rlm@0:
rlm@0: