Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

perl, how to print out all the cgi fom values

Posted on 2011-02-15
2
Medium Priority
?
545 Views
Last Modified: 2013-12-25
how do I print out all the form values?
0
Comment
Question by:rgbcof
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 1000 total points
ID: 34899088
Try this.  You may need to fix the first line in the file depending on your server setup.

(try it here: http://www.sjklein.com/dumpParms.pl?foo=bar&bar2=foo)

#!/usr/bin/perl -w

sub HttpUnescape
{
	my $x = shift (@_);
	my $y = '';
	$x =~ s/\+/ /g;			# restore blank characters
	while ( $x =~ /\%([0123456789ABCDEF][0123456789ABCDEF])/i ) { $y .= $` . chr (hex($1)); $x = $'; }
	return $y . $x;
}

sub GetArgs
{
	$x = $ENV{'REQUEST_URI'};
	if ( $x =~ /\?/ ) { $x = $'; }			# split at ?, if any, and keep second part
	if ( $x =~ /\/\&/ ) { $x = $'; }		# split at /&, if any, and keep second part
	$x =~ s/^\///;							# trim leading slash, if any
	$x =~ s/^\&//;							# trim leading &, if any

	@argpairs = split (/\&/, $x);
	foreach $argpair (@argpairs)
	{
		if ( $argpair =~ /\=/ )
		{ 
			$key = lc($`);			# all argument are lower case

			$x = HttpUnescape($');
			$x =~ s/^\s+//;			# remove leading space
			$x =~ s/\s+$//;			# remove trailing space
			$x =~ s/\s+/ /g;		# normalize whitespace
			$arg{$key} = $x;
		}
		else { $arg{$argpair} = 1; }
	}
}

sub GetPostParms
{
	$postData = join ('', <>);
	@postParms = split (/\&/, $postData);

	foreach $postParm (@postParms)
	{
		($parmName, $x) = split(/\=/, $postParm);
		$x = HttpUnescape($x);
		$x =~ s/\r//g;
		$postParm{$parmName} = $x;
	}
}

GetArgs();
GetPostParms();

print q{Content-type: text/html

<html><body><pre>};

foreach $key (sort(keys(%ENV))) { print "ENV $key = $ENV{$key}\n"; }
print '<hr>';
foreach $key (sort(keys(%arg))) { print "CGIARG $key = $arg{$key}\n"; }
print '<hr>';
foreach $parmName (sort(keys(%postParm))) { print "POSTPARM $parmName = $postParm{$parmName}\n"; }

print q{</body></html>};

Open in new window

0
 

Author Closing Comment

by:rgbcof
ID: 34899803
wow, very detailed answer.   Thanks,
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question