Solved

perl, how to print out all the cgi fom values

Posted on 2011-02-15
2
535 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 250 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Log File Creation with Header and Footer 17 161
Find unused columns in a table 12 75
Select SamAccountName - powershell script 2 19
Powershell Split 18 29
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

730 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