Addition using Perl/CGI in Ubuntu
Information Technology December 3rd, 2009If Apache web server has installed in your system, you can run Perl/CGI script successfully. Create a html file and perl script using following steps.
Step 1: Creating a web page add.html
Open your console and type:
$ sudo gedit /var/www/add.html
Copy the lines below in the file and save it.
<html>
<head>
<title>Addition of two numbers.</title>
</head>
<body>
<br><br><br><br><br>
<form action=’cgi-bin/add.pl’ method=’post’ enctype=’multipart/form_data’>
<table border=’0′ align=’center’>
<tr><td colspan=’2′ align=’center’>
<b>Adding Two Numbers</b>
</td></tr>
<tr>
<td>Enter the first value:</td>
<td><INPUT TYPE =’text’ NAME=’n1′></td>
</tr>
<tr>
<td>Enter the second value:</td>
<td><INPUT TYPE =’text’ NAME=’n2′></td>
</tr>
<tr><td colspan=’2′ align=’center’>
<INPUT TYPE =’submit’ VALUE=’ADD’ NAME=’submit’>
</td></tr>
</table>
</form>
</body>
</html>
Step 2: Creating a perl script add.pl
Open your console and type:
$ sudo gedit /usr/lib/cgi-bin/add.pl
$ sudo chmod a+x /usr/lib/cgi-bin/add.pl
The command chmod a+x is used to allow permission to run the script. Without using this command your program will not run. !!!
Copy the lines below in the file and save it.
#!/usr/bin/perl -w
use CGI;
CGI::ReadParse();
$numb1 = $in{’n1′};
chomp($numb1);
$numb2 = $in{’n2′};
chomp($numb2);
$numb3=$numb1+$numb2;
CGI::PrintHeader();
print “content-type:text/html\n\n”;
print “<HTML>\n”;
print “<head><title>Addition of two numbers</title></head>\n”;
print “<body>\n”;
print “<br><br><br><br><br><center>Addition of $numb1 and $numb2 is $numb3.</center>\n”;
print “</body>\n”;
print “</html>\n”;
Step 3: Running the program
Open web browser and hit address http://localhost/add.html to run the Perl/CGI program.
January 22nd, 2010 at 4:28 AM
Good posting. I appreciate you for posting it. Keep up the great site.
March 7th, 2010 at 6:57 PM
Terrific work! This is the type of information that should be shared around the web. Shame on the search engines for not positioning this post higher!
March 18th, 2010 at 1:58 AM
I see a great improvement in your writing, I’d love to get in touch. Keep up the great work! Your writing is very inspirational for someone who is new to this type of stuff.
April 30th, 2010 at 5:48 AM
Good stuff. Nice to read some well written content. A big gap between them.
May 2nd, 2010 at 6:36 PM
There is obviously a lot to know about this.
May 3rd, 2010 at 12:59 PM
Such a usefule blog wow !!!!
May 3rd, 2010 at 5:05 PM
Great articles & Nice a site!!
May 4th, 2010 at 12:41 PM
Great articles & Nice a site!!
May 4th, 2010 at 8:16 PM
good thanks a lot,this is very useful!!
May 5th, 2010 at 1:34 PM
Hey very nice blog!!
May 6th, 2010 at 3:44 PM
Such a usefule blog wow !!!!
May 6th, 2010 at 10:37 PM
Hey nice blog, i have bookmarked the site for later use, thanks.
May 7th, 2010 at 8:54 AM
good thanks a lot,this is very useful!!
May 7th, 2010 at 7:07 PM
Your blog is so informative ?keep up the good work!!!!
May 7th, 2010 at 7:44 PM
This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.
May 8th, 2010 at 1:31 PM
thanks !! very helpful post!
May 15th, 2010 at 10:09 AM
Hello,just found your Blog when i google something and wonder what hosting do you use for your wordpress,the speed is more faster than my wordpress, i really need to know it.will back to check it out,i appreciate it!
May 18th, 2010 at 3:37 PM
Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader
May 25th, 2010 at 9:30 PM
Good! Thank you! I always wanted to write in my site something like that. Can I take part of your post to my blog?