Hi, I need to replace the nth occurence of a character in a string.Currenly m tryng to replace the 2nd comma in ths string.I have used the following code for that.Can anyone give a better suggestion?
my $count = 3; my $str = "a,b,c,d"; $str =~ s/(,)/--$count == 1 ? "|":$1/ge; print $str;
In reply to Replace the nth occurence by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |