Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Replacing a given character starting with the xth occurence in a string

by sachmet (Scribe)
on May 21, 2001 at 04:28 UTC ( #81888=note: print w/replies, xml ) Need Help??


in reply to Replacing a given character starting with the xth occurence in a string

Method without using temporary variables:
my $x = 3; my $chr = 'e'; my $newchr = '1'; my $str = "Terence and Philip are sweet!\n"; print $str; $x--; 1 while ($str =~ s/(([^$chr]*$chr){$x}([^$chr]*))$chr/$1$newchr/g); print $str;
  • Comment on Re: Replacing a given character starting with the xth occurence in a string
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2021-04-20 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?