Solved

Replace function in perl

Posted on 2004-09-02
5
1,631 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

756 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