The following Perl/CGI form example asks a user to enter two integers and upon the submission an addition is performed on both submitted integers.

Note: to handle both integers the "post" method action is set to itself. Meaning that a HTML post method will be created in a following format:

form action="/cgi-bin/perl-cgi-form.cgi" enctype="multipart/form-data" method="post"

Save a following perl-cgi-form.cgi code into /usr/lib/cgi-bin/:

#!/usr/bin/perl -T 
use strict; 
use CGI qw/:standard/; 
print header, 
start_html('Perl/CGI form example'), 
start_form, 
	"Integer 1: ",textfield('num1'), 
	br, 
	"Integer 2: ",textfield('num2'), 
	br, 
	submit, 
end_form, 
hr; 
 
print param('num1')+param('num2'), 
	p, 
	end_html; 
exit; 

make it executable:

# chmod 755 /usr/lib/cgi-bin/perl-cgi-form.cgi

by navigating your browser to the above Perl/CGI program you should see a page similar to the one below. Currently the form can handle only integers:

PERL CGI FORM example



Free Linux eBooks

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top