Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi i am a beginner in perl.I have the following code to replace the 2nd comma in a line with "|".
$line="1,2,3"; my $ft_count = 0; $ft_count++ while($line =~ m/[,]/g); if($ft_count==2) { my $n = 2; my $r = $n - 1; $line =~ s/((?:,.*?){$r}),/${1}|/; } print $line;
Output will be 1,2|3 I need to reuse the code in such a way that the input is "1|2|3" and i need to replace the 2nd "|" with comma.I tried changing the regular expression in the above code.But it didnt work.Can anyone plz help
??
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replacing with comma
by Athanasius (Archbishop) on Dec 27, 2012 at 06:51 UTC | |
|
Re: Replacing with comma
by muba (Priest) on Dec 27, 2012 at 06:57 UTC | |
|
Re: Replacing with comma
by 2teez (Vicar) on Dec 27, 2012 at 07:37 UTC | |
|
Re: Replacing with comma
by 7stud (Deacon) on Dec 27, 2012 at 10:33 UTC | |
|
Re: Replacing with comma
by Anonymous Monk on Dec 27, 2012 at 12:19 UTC |