Welcome to WebmasterWorld Guest from 52.91.39.106

Forum Moderators: coopster & jatar k & phranque

Any problem with parsing param() to % GET ?

     
7:39 am on May 8, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Mar 15, 2013
posts: 1095
votes: 103


Since I've gotten a lot more use to using PHP over the last few years, would there be any reason that I shouldn't parse param() to %_GET, like so:

%_GET = map { $_ => get_data($_) } param;
sub get_data {
my $name = shift;
my @values = param($name);
return @values > 1 ? \@values : $values[0];
}


This would let me refer to GET variables as $_GET{'foo'}, about as similar to PHP's $_GET['foo'] as I think I can get.

Or is there a better way to do the same thing?
11:42 am on May 8, 2019 (gmt 0)

Administrator from US 

WebmasterWorld Administrator brett_tabke is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 21, 1999
posts:38246
votes: 108


I've rarely use CGI in perl. I usually do it by hand:

$fileupload++ if lc($ENV{CONTENT_TYPE}) =~ m'multipart/form-data;'; #ck if file upload - bail if it is
if (!$fileupload) {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$buffer = $ENV{QUERY_STRING} if (length($buffer) < 3);
if (length($buffer)> 130000) {
die("Request to receive too much data\n"); #die if spammers and jammers
exit;
}

@pairs = split(/&/, $buffer); #get name/value pairs

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$name =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; #clean junk chars
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value; #now passed vars are in $FORM{}
}
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members