Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Substituting a dot

Status
Not open for further replies.

LuckyKoen

Programmer
Feb 14, 2005
57
BE
I have $string that contains "1.2.3"

I would like to get the . out but with $string =~ s/./_/g the numbers are also replaced with _ instead of only the dots.

How do I make sure that only the dots are replaced and not every character in $string ?
 
For regexs, '.' means any single character, but if you escape it ('\.') it's a literal period. Try:

Code:
$string =~ s/\./_/g;
 
Since it's single-character replacement you need, it's possibly better with a straight transliteration, rather than a regexp:
Code:
$string =~ tr/./_/;
Don't let looks deceive you - it's not a regexp - hence why I haven't escaped the dot, as it has no special meaning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top