Forum Moderators: coopster & phranque

Message Too Old, No Replies

Perl and POST requests

how to filter out "+"?

         

PsychoTekk

11:56 am on May 23, 2003 (gmt 0)

10+ Year Member



i have a little sitesearch perl script that reads the form values
like this:

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
$FORM{$name} = $value;}

i'm not a perl pro so i just use this common peace of code, however,
when the formfield with the terms to search for looks like this
"term1 + term2" a cgi error occurs.
how can i fiter out a "content plus" without to affect the
"splitting plus" between each search term?

thanks in advance!

BCMG_Scott

12:57 pm on May 23, 2003 (gmt 0)

10+ Year Member



what error are you getting? Filtering the + on the value should not be a problem in and of itself. It may be the manner in which you are using value. Also if you send a literal plus sign through a form it will get escaped to a %nn value. A plus sign in the query data will ALWAYS be a space.

Scott Geiger

PsychoTekk

2:04 pm on May 23, 2003 (gmt 0)

10+ Year Member



in this line the error occurs:
if ($string =~ /$term/)
and this is the error message:
"Quantifier follows nothing before HERE mark in regex m/+ << HERE / at search.pl line 69."
it just happens if there are spaces between the terms and the +:
"term1 + term2"

i tried
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/+//g;
$FORM{$name} = $value;}
but it doesn't work :(
what do i have to put where to delete the literally "+"?
thanks

BCMG_Scott

4:20 pm on May 23, 2003 (gmt 0)

10+ Year Member



AHHHH - + is a special character in REGEXP. That's the problem. You need to do something like:

if ($string =~ /\Q$term\E/) {...

the \Q will disable the meta charater pattern match until \E.

Scott

PsychoTekk

4:32 pm on May 23, 2003 (gmt 0)

10+ Year Member



thanks Scott, works fine now! :)