Solved

Replace function in perl

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

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
Syslog text file into database or into .CSV 19 110
perl rename 2 142
Perl for loop for 2000 ms 7 97
Control Number of Log Files -Perl 7 55
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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

19 Experts available now in Live!

Get 1:1 Help Now