#!/opt/perl524 use strict; use warnings; main() if ( !caller() ); sub main { use CGI; my $cgi = CGI->new; if ( !$cgi->param ) { print $cgi->header, my_form( 'action_url' => $cgi->url() ); exit; } my $num1 = $cgi->param('num1') || ''; my $num2 = $cgi->param('num2') || ''; # Next, add the value of the incoming parameters and display a result (not shown here) # my $sum = add_two_numbers( $num1, $num2 ); # Then print a result to the web browser and display a fresh form under the result (not shown here) exit; } ## end sub main sub add_two_numbers { my ( $num1, $num2 ) = @_; return $num1 + $num2; } sub my_form { my %params = @_; my $action_url = $params{'action_url'} || ''; die "No URL specified for the 'action' attribute of the form, can't continue" if ( !$action_url ); my $form = qq| Add Two Numbers

Add Two Numbers

Enter some first number:

Enter some second number:

|; } ## end sub my_form