Luinrandir Hernson wrote:

> Below is the code i'm using to filter out non alphanumeric charecters... however 
>when i type....
> ?!$BOB 
> yeilds this:
> -_3f_21_24bob-
> 
> The ?!$ should be stripped away and come back empty, not
> _3f_21_24
> ANY ideas as to what I'm doing wrong???
> I'm asking for an email address.
> 
> my $eaddress = "";
> read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
> $eaddress = $buffer;
> ###############
> @list=split(/&/,$eaddress);
> $eaddress=$list[0];
> @list=split(/\=/,$eaddress);
> $eaddress=$list[1];
> 
> $eaddress=~tr/A-Z/a-z/;                ##changes everything to lowercase !!! THIS 
>WORKS !!!
> $eaddress=~tr/a-z0-9/_/c;             ##changes everything but a-z 0-9 to _


since i didn't see a response to this, i'll attempt to help you out.

i think the reason you're having this problem is because 
non-alphanumeric characters passed in an html form are encoded.  so if 
you were to type

cgi-bin/index.cgi?name=fliptop&comment=yikes!!

in your browser, when the key-value pairs make it to your script the 
'yikes!!' will be encoded and will actually be 'yikes%21%21'.  as you 
can see, 21 will not be filtered out by your tr/// (but the % signs will 
be).

the best way (imho) to tackle this is to abandon parsing the query 
string yourself and use cgi.pm.  it will take care of all the html 
decoding for you.  here's how i'd rewrite your script (note, this has 
not been tested):

# begin
use CGI;
my $q = new CGI;

# substitute your form element name in for 'eaddress'
my $eaddress = lc $q->param('eaddress');
$eaddress =~ s/a-z0-9/_/g;
#end

note that the param() method in cgi.pm will return the value for the key 
you pass to it (in list context, it will return all values).  also note 
i used lc() instead of a regex to convert the value to lowercase.

for more information about using cgi.pm, type

perldoc cgi

at a command prompt.  you can get cgi.pm from cpan by pointing your 
browser to

http://search.cpan.org/search?dist=CGI.pm


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to