Last updated on January 19th, 2022 at 11:26 am

In this tutorial we will see how to get the query string value using very simple perl CGI script.

When we hit a URL from the web browser with a query string say
In which program=php is the query passed.Now we will see how we get the same value using perl CGI script.

Please note: you don’t have to really run a webserver to test the the script below. You can even use command line like this

# ./ program=php

Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" lang="en-US" xml:lang="en-US">
<title>Cgi Query String Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<h1>Values Passed</h1>
<table border="1" cellspacing="0" cellpadding="0">

As you can see I passed parameter as program=php and the output can be seen in this section of the script


Complete Code

#Script From
use strict;
use CGI;
my $cgi = new CGI;
$cgi->header() .
$cgi->start_html( -title => 'Cgi Query String Results') .
$cgi->h1('Values Passed') . "\n";
my @params = $cgi->param();
print '<table border="1" cellspacing="0" cellpadding="0">' . "\n";
foreach my $parameter (sort @params) {
print "<tr><th>$parameter</th><td>" . $cgi->param($parameter) . "</td></tr>\n";
print "</table>\n";
print $cgi->end_html . "\n";
exit (0);

Leave a Reply

Your email address will not be published. Required fields are marked *