in reply to Replace the nth occurence
A general solution:
my $nth = 4; my $str = 'a=>bb=>ccc=>dddd=>eeeee=>ffffff'; while ($str =~ /=>/g) { if (--$nth == 0) { substr($str, $-[0], $+[0] - $-[0], '~~|~~'); last; } } print "$str\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Replace the nth occurence
by AnomalousMonk (Archbishop) on Nov 21, 2012 at 22:49 UTC |
In Section
Seekers of Perl Wisdom