Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1649
  • Last Modified:

Replace function in perl

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
jacobcolton
Asked:
jacobcolton
2 Solutions
 
jacobcoltonAuthor Commented:
Also is there a way to change the whole string to lower case?

Thanks,

Jacob
0
 
naschCommented:
$name =~ s/ /_/g; will Substitute all ' ' with _ Globablly
$name = lc($name); will Lower Case $name
0
 
geotigerCommented:
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
 
TintinCommented:
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
 
jacobcoltonAuthor Commented:
Nope, that was all I was trying to do.

Many Thanks for all your help!

Jacob
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now