Solved

Replace function in perl

Posted on 2004-09-02
5
1,627 Views
Last Modified: 2008-02-01
I am very new to perl and just making a few amendments to an old script I want to replace all the space (%20) in a string ($name) to underscores (_) is there a way of doing this with one line of code, like in asp?

Thanks,

Jacob
0
Comment
Question by:jacobcolton
5 Comments
 

Author Comment

by:jacobcolton
ID: 11965256
Also is there a way to change the whole string to lower case?

Thanks,

Jacob
0
 
LVL 2

Assisted Solution

by:nasch
nasch earned 100 total points
ID: 11965293
$name =~ s/ /_/g; will Substitute all ' ' with _ Globablly
$name = lc($name); will Lower Case $name
0
 
LVL 12

Accepted Solution

by:
geotiger earned 400 total points
ID: 11967376
Here is a little modification to nasch's code:

$name =~ s/\%20/_/g;     # replace all %20 to _
$name = lc($name);         # covnert to lower case $name
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11968610
Could you please explain the larger picture here.  I suspect you are trying to solve a problem by perhaps not using the most efficient method.
0
 

Author Comment

by:jacobcolton
ID: 11970833
Nope, that was all I was trying to do.

Many Thanks for all your help!

Jacob
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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 …
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

810 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