Gossamer Forum
Home : General : Perl Programming :

Wanna Help about CGI

Quote Reply
Wanna Help about CGI
Script code:

if ($ENV{'REQUEST_METHOD'} eq 'GET')
{$buffer=$ENV{'QUERY_STRING'};
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$str{$name} = $value;}}

There is my problem, i want using =~tr function change + to %2B ,
but i can't do it, under is my trying ,


if ($str{'name'}=~tr/+/%2B/) {print "Hello $str{'name'}\n\n";exit;}

when i input C++ inside the HTML form text field then run it....

the result is give me Hello C%%

anotherway i try to using \ front of the %2B ,that means is

if ($str{'name'}=~tr/+/\%2B/) {print "Hello $str{'name'}\n\n";exit;}

oh, it still print the result is Hello C%%

Somebody can teach me using which function to modify this script can be
change + to %2B of the $str{$name} on my case???

Thank
Quote Reply
Re: [PDK1999] Wanna Help about CGI In reply to
I'd suggest removing that code and using CGI.pm - its much more up to date.
Quote Reply
Re: [PDK1999] Wanna Help about CGI In reply to
Can all be replaced with CGI.pm. Example code;

Code:
use CGI;
my $IN = new CGI;

print $IN->header();

my $var1 = $IN->param('var1');
my $var2 = $IN->param('var2');
my $var3 = $IN->param('var3');

Its sooo much simpler, and a lot less buggy than writing your own parsing code :)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates