Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Replace all . with _ in a string

by DigitalKitty (Parson)
on Dec 23, 2003 at 19:22 UTC ( [id://316690]=note: print w/replies, xml ) Need Help??


in reply to Replace all . with _ in a string

Hi.
#!/usr/bin/perl -w use strict; my $str = "I like to eat pizza. Every friday, I do."; $str =~ s/\./_/g; print $str; Output: C:\>perl pg61.pl I like to eat pizza_ Every friday, I do_


I had to 'backslash' the period to prevent it from matching any character in the string. The 'g' on the end of the substitution means 'throughout the whole string as opposed to only the first period'.

Hope this helps,
-Katie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://316690]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-19 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found