Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Replace function in perl

Posted on 2004-09-02
5
1,628 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

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

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…

856 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