getting rid of...

Posted on 1998-06-22
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/+/ /;

Is this the reason all my non alphabetic and numeric characters endup like this?
Question by:idadan
  • 3
  • 2
  • 2

Author Comment

ID: 1207963
Edited text of question

Expert Comment

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/\\\+/+/;


Author Comment

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.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Accepted Solution

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)


Author Comment

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

Expert Comment

ID: 1207968
LVL 84

Expert Comment

ID: 1207969
#should have changed "What%27s up%3f" back to "What's up?"

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syslog text file into database or into .CSV 19 159
Perl - Mawk 2 101
perl CPAN issue 3 117
combine multiple lines 2 67
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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

828 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