Solved

Killing passed text...

Posted on 2000-03-21
7
115 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now