Solved

Substituting whitespace for +

Posted on 2002-03-27
2
264 Views
Last Modified: 2010-05-18
Hi,
I am trying to replace all the + in a string for whitespace. But I can't seem to be able to find the + in the string.
Any ideas?

Thanks,
Angelmoon
0
Comment
Question by:angelmoon
2 Comments
 
LVL 5

Expert Comment

by:Peewee
ID: 6899887
angelmoon,
is this what you want:

my $var = 'tie+tie';

$var =~ s/\+/ /ig;
print "var:$var\n";

regards
Peewee
0
 
LVL 5

Accepted Solution

by:
Sapa earned 100 total points
ID: 6899948
angelmoon,

it looks like you attempts to decode URL-encoded string.
Such strings can also contain %NN escape codes, which
represents characters with hexadecimal code NN. For example:
* is %2a, / is %2f etc.

There are at least 3 ways to decode such strings:

1. using URI::Escape module

use URI::Escape;
$decoded = uri_unescape($encoded);

2. using CGI module

use CGI;

$decoded = CGI::unescape($encoded);

3. Do it manually :(

$encoded =~ tr/+/ /;
$encoded =~ s/%([0-9a-fA-F]{2})/chr hex($1)/ge;

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange perl issue 6 126
How to strip .csv from file name 9 78
Perl string replace for refred url 9 59
Perl script to find new files and compress those new files 5 81
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

861 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

25 Experts available now in Live!

Get 1:1 Help Now