Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://81888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-18 17:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found