robert@0: #!C:/strawberry/perl/bin/perl.exe robert@0: robert@0: # this is an example of using subs (not coderefs) for your perljax robert@0: # functions robert@0: # robert@0: # NB The CGI::Ajax object DOES NOT need to follow the function robert@0: # declarations, as it does in the coderef example robert@0: robert@0: use strict; robert@0: use CGI::Ajax; robert@0: use CGI; robert@0: robert@0: my $q = new CGI; robert@0: my $pjx = CGI::Ajax->new( 'myfunc' => \&exported_fx); robert@0: print $pjx->build_html($q,\&Show_Form); # this outputs the html for the page robert@0: robert@0: sub exported_fx { robert@0: my $value_a = shift; robert@0: my $value_b = shift; robert@0: $value_a = "" if not defined $value_a; # make sure there's def robert@0: $value_b = "" if not defined $value_b; # make sure there's def robert@0: robert@0: if ( $value_a =~ /\D+/ or $value_a eq "" ) { robert@0: return( $value_a . " and " . $value_b ); robert@0: } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) { robert@0: return( $value_a . " and " . $value_b ); robert@0: } else { robert@0: # got two numbers, so lets multiply them together robert@0: return( $value_a * $value_b ); robert@0: } robert@0: } robert@0: robert@0: sub Show_Form { robert@0: my $html = ""; robert@0: $html .= < robert@0: CGI::Ajax Example robert@0: robert@0: robert@0:
robert@0: Enter something:  robert@0:
robert@0: robert@0: Enter something else:  robert@0:
robert@0: robert@0:
robert@0:
robert@0:
robert@0:
robert@0: robert@0: robert@0: EOT robert@0: return $html; robert@0: }