Gossamer Forum
Home : General : Perl Programming :

remove underscores, dashes from query

Quote Reply
remove underscores, dashes from query
Hello,

I also need to remove "underscores" and "dashes" and "all other characters" from a query string and return only keywords with spaces, when using the encode_address as below.

sub encode_address {
my ($toencode) = shift;
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
return $toencode;
}

How to do?

thanks
Quote Reply
Re: [socrates] remove underscores, dashes from query In reply to
I don't know if this is it but wouldn't it be..

s{ /\_*$/ }g;

and

s{ /\-*$/ }g;
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central
Quote Reply
Re: [nolimit] remove underscores, dashes from query In reply to
No :)

Can't ypu just use CGI.pm?


Last edited by:

RedRum: Oct 2, 2001, 3:35 AM
Quote Reply
Re: [RedRum] remove underscores, dashes from query In reply to
Can this be simplified?

my ($cat_main_clean) = ($category_clean =~ m,^([^:]+),);
$cat_main_clean =~ tr/-/ /;
$cat_main_clean =~ tr/_/ /;

thanks
Quote Reply
Re: [socrates] remove underscores, dashes from query In reply to
Well you could change:

$cat_main_clean =~ tr/-/ /;
$cat_main_clean =~ tr/_/ /;


to.....

$cat_main_clean =~ s/[-_]/ /g;
Quote Reply
Re: [RedRum] remove underscores, dashes from query In reply to
thanks, that will save a step, I wanted to do it in one step.

So, what is redrum - is it different from redwine Sly? I did not realize you are paul and you changed your name.

Last edited by:

socrates: Oct 4, 2001, 1:53 PM
Quote Reply
Re: [socrates] remove underscores, dashes from query In reply to
I'm not sure it can be done in one step as you are matching and then substituting.

Just watch someone prove me wrong.....hehe Blush

Quote:
I did not realize you are paul and you changed your name.

Thats why I changed it - I was hoping people would no longer associate me with "PaulWilson" (that username brings back bad memories).