Solved

Killing passed text...

Posted on 2000-03-21
7
118 Views
Last Modified: 2010-03-05
This should be simple: is there a way to supress the output of the special escape characters in Perl?  In other words, if the user enters something like:

"I like to eat cheese!"

Can I keep it from being passed as:

"I+like+to+eat+cheese%21"?  

I need to output the text back to HTML, and it's obviously no good to me like this.  Do I just have to do an s///?  Or is there an easier way?
0
Comment
Question by:Raydot
7 Comments
 
LVL 4

Expert Comment

by:binkzz
ID: 2639788
You can't pass it any other way, but you can decode it by using two regular expressions:

$key=~s/\+/ /g;
$key=~s/%([0-9a-fA-f]{2})/pack("c",hex($1))/ge;

Binkzz
0
 
LVL 84

Expert Comment

by:ozo
ID: 2640105
why not pack("H*",$1)?
0
 
LVL 4

Expert Comment

by:binkzz
ID: 2640126
It works and doesn't particulary slow down the system
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
ID: 2640189
if you have the URI::Escape PERL module, try this....

if you dont, i would suggest that you install the same from www.cpan.org.

its very useful, since you dont have to worry about all the special characters to escape and unescape.

==============escape.pl
#!/usr/local/bin/perl

use URI::Escape;

$str="I like to eat cheese!";

print "Original string ",$str,"\n";
$safe = uri_escape($str);
print "After Escaping ",$safe,"\n";

$str  = uri_unescape($safe);
print "After Un-Escaping ",$str,"\n";
0
 
LVL 4

Expert Comment

by:binkzz
ID: 2640235
Can I just find out what's actually wrong with my solution?

Binkzz
0
 
LVL 3

Author Comment

by:Raydot
ID: 2640628
Who said there was anything wrong with your solution?  I think man and ozo are just offering alternatives.

I'll have to check for that URI::Escape module...Ozo, I don't really understand your pack solution.  Thanks!
0
 
LVL 3

Author Comment

by:Raydot
ID: 2810997
Did y'all think I forgot about this question?  Thanks for all your help!
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cpan issue 1 65
pipe to sed or perl, please help 5 130
syslog unix file 20 76
Perl tar error 8 67
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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