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