Perl Get Post method

Get value from Get and Post methods


In HTTP there are two methods GET and POST. We are passing value to server using these two methods. In server we have to get the value from Client. The Below code will give you the result.
Get Method in Perl example code

#!D:\Perl\bin\perl
print "Content-type: text/html

";

sub populateQueryFields {
%queryString = ();
my $tmpStr = $ENV{ "QUERY_STRING" };
@parts = split( /&/, $tmpStr );
foreach $part (@parts) {
( $name, $value ) = split( /=/, $part );
$queryString{ "$name" } = $value;
}
}

&populateQueryFields;
$firstName = $queryString{ "fname" };
$lastName = $queryString{ "lname" };
print $firstName;
print $lastName;

Post Method in Perl example code

sub populatePostFields {
%postFields = ();
read( STDIN, $tmpStr, $ENV{ "CONTENT_LENGTH" } );
@parts = split( /&/, $tmpStr );
foreach $part (@parts) {
( $name, $value ) = split( /=/, $part );
$value =~ ( s/%23/#/g );
$value =~ ( s/%2F///g );
$postFields{ "$name" } = $value;
}
}

Use the HTML code the Test the program

<form action="script.pl" method="post">
<input type="TEXT" name="fname">
<input type="TEXT" name="lname">
<input type="SUBMIT" value="SUBMIT">
</form>

&populatePostFields;
$firstName = $postFields{ "fname" };
$lastName = $postFields{ "lname" };

print $firstName;
Print $lastName;


Related Topic Get form values in perl
PHP Programming Best Practices
How to get Form Values
PHP Mysql New User Registration Code Example
Perl Passing Hash as Parameter Argument
Perl  

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback