stephanm has asked for the wisdom of the Perl Monks concerning the following question:
in the code below I try to put in single quotes all the numbers in the second set of parenthesis of $string.
However, the s///g command does not seem to act on the g modifier.
Who has got some clues?
Thanks.
$string = "(1,2,3) XXX (1,2,3)"; for ($string) { s/XXX \(/XXX \('/; s/(XXX [^,]+),/$1';'/g; s/;/,/g; s/\)$/'\)/; } print $string, "\n"; # Produces output: (1,2,3) XXX ('1','2,3')
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help with substitue /g
by Anonymous Monk on Apr 11, 2010 at 10:12 UTC | |
|
Re: Need help with substitue /g
by jwkrahn (Abbot) on Apr 11, 2010 at 15:29 UTC | |
|
Re: Need help with substitue /g
by Anonymous Monk on Apr 11, 2010 at 10:17 UTC | |
|
Re: Need help with substitue /g
by johngg (Canon) on Apr 11, 2010 at 23:37 UTC | |
|
Re: Need help with substitue /g
by 7stud (Deacon) on Apr 12, 2010 at 05:24 UTC | |
|
Re: Need help with substitue /g
by JavaFan (Canon) on Apr 12, 2010 at 10:59 UTC | |
|
Re: Need help with substitue /g
by AnomalousMonk (Archbishop) on Apr 12, 2010 at 11:01 UTC |