Using GET Methods in Perl

PERLServer Side ProgrammingProgramming Scripts

<p>Here is a simple URL which will pass two values to hello_get.cgi program using GET method.</p><p>;last_name=ALI</p><p>Below is&nbsp;hello_get.cgi&nbsp;script to handle input given by web browser.</p><pre class="prettyprint notranslate">#!/usr/bin/perl local ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text $ENV{&#39;REQUEST_METHOD&#39;} =~ tr/a-z/A-Z/; if ($ENV{&#39;REQUEST_METHOD&#39;} eq &quot;GET&quot;) { &nbsp; &nbsp;$buffer = $ENV{&#39;QUERY_STRING&#39;}; } # Split information into name/value pairs @pairs = split(/&amp;/, $buffer); foreach $pair (@pairs) { &nbsp; &nbsp;($name, $value) = split(/=/, $pair); &nbsp; &nbsp;$value =~ tr/+/ /; &nbsp; &nbsp;$value =~ s/%(..)/pack(&quot;C&quot;, hex($1))/eg; &nbsp; &nbsp;$FORM{$name} = $value; } $first_name = $FORM{first_name}; $last_name = $FORM{last_name}; print &quot;Content-type:text/html\r \r &quot;; print &quot;&lt;html&gt;&quot;; print &quot;&lt;head&gt;&quot;; print &quot;&lt;title&gt;Hello - Second CGI Program&lt;/title&gt;&quot;; print &quot;&lt;/head&gt;&quot;; print &quot;&lt;body&gt;&quot;; print &quot;&lt;h2&gt;Hello $first_name $last_name - Second CGI Program&lt;/h2&gt;&quot;; print &quot;&lt;/body&gt;&quot;; print &quot;&lt;/html&gt;&quot;; 1;</pre>
Updated on 02-Dec-2019 08:09:56