On Wed, Aug 06, 2003 at 11:13:15PM -0500 Ben Jacobs-Swearingen wrote: > Hello all, this is my first post to this group, and I hope it isnıt > inappropriate. Anyway I have the following code in a CGI Iım working on, > itıs supposed to translate the ugly %(hexhex) markers for non-alphanumeric > characters back into normal text and assign the results to elements of an > array. In the following script $in has a sample line of form input to give > you a better idea of whatıs going on: > > $in = > "protocol=n&server=www.a.this%2Fis%2F%7Esilly.html®ex=babo%5Bd%7Ce%5D"; > @in = split(/&/,$in);
There is a nice module called CGI.pm that does that for you. It's a core module, so use it instead of doing it the hard (and often wrong) way. use CGI; my $cgi = CGI->new; for ($cgi->param) { print "$_: ", $cgi->param($_); } The param() method returns a list of all parameters when called in list-context (as in the above for signature) and the value of a parameter when it is passed as argument. See 'perldoc CGI' for details. If you want the above to parse given query strings, you can do it like this: my $cgi = CGI->new("protocol=n&server=www.a.this%2Fis%2F%..."); ... Just use 'CGI->new()' if you want your script act as a CGI script. The module will then do the right thing (that is, distinguish between POST and GET for example etc.). > When I try this at home (on MacPerl) and at school (using standard Unix Perl > in OSX) the script works perfectly; however when I try to run it as a CGI on > the server (which is running Perl 5.006001) I get a blank page: presumably > the script is not generating any errors (at least according to the error > log), but it isnıt giving me any results either. Does anyone have any idea > why that might be? Also Iım a total novice at Perl, so please no rude > comments about my awkward coding (instructive comments about my awkward > coding would be more than welcome). Thanks in advance! I didn't look too closely at the code but it appeared to have a few red-herrings in it. To translate a URI-escaped string back to its plain representation, you can use this substitution: $_ = "www.a.this%2Fis%2F%7Esilly.html"; s/%(\w\w)/chr(hex($1))/ge; print $_; It grabs two characters following a %, turns these hex-numbers into decimals and looks the corresponding character up using chr(). You need the /e modifier here, because the right-hand side of the substitution is not the translation string but instead Perl code whose return value is supposed to be the string. Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]