Solved

getting rid of...

Posted on 1998-06-22
7
212 Views
Last Modified: 2010-03-04
I'm making a bbs and need advice on a bit of code.  Right now whenever anyone submits there post the subject looks like What%27s+up%3f instead of What's+up?  I use this to encode all white spaces to + signs
$Subject =~ s/([^\w ])/'%'.unpack('H*',$1)/eg;
$Subject =~ tr/ /+/;
and this to get it back from + signs to spaces
$Subject=~tr/+/ /;
$Subject=~s/%(\w\w)/pack('H*',$1)/eg;

Is this the reason all my non alphabetic and numeric characters endup like this?
0
Comment
Question by:idadan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

by:idadan
ID: 1207963
Edited text of question
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1207964
You told it to!  If all you want to do is convert any white space to a + sign, just use

$Subject =~ s/\s+/+/;

That will take "What's     up?"  or "What's up?" and change it to "What's+up?"

Of course, then you have the problem of someone actually typing in '+', so preface the above line with

$Subject =~ s/\+/\\+/;

To undo that mess, use

$Subject =~ s/([^\\])\+/\1 /;
$Subject =~ s/\\\+/+/;

0
 

Author Comment

by:idadan
ID: 1207965
Ok, the question is why is it changing, say a, question mark to %3f NOT why is it changing + signs to " " and visa virsa.  Sorry for the misunderstanding.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1207966
If the question is why is it changing any character NOT found in a word to a percent sign followed by the hex string of that character (high nybble first?) Because that is exactly what

s/([^\w ])/'%'.unpack('H*',$1)/eg;

does!!!!  (In case you don't know, the ascii code for a question mark is 3f)

0
 

Author Comment

by:idadan
ID: 1207967
Great, thanks for your help.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1207968
     
0
 
LVL 84

Expert Comment

by:ozo
ID: 1207969
$Subject=~s/%(\w\w)/pack('H*',$1)/eg;
#should have changed "What%27s up%3f" back to "What's up?"
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question