Andrew Curry wrote:
Think

s/(\,+\s*)+/,/g;

Commas are not special in a regular expression so there is no need to escape them. You are using capturing parentheses but are not using the string captured in $1, better to use non-capturing parentheses.

s/(?:,+\s*)+/,/g;


A modified pattern inside a modified group is inefficient and could bomb if the string is long enough:

$ perl -le'
$_ = ", " x 100_000;
s/(?:,+\s*)+/,/g;
print;
'
Segmentation fault (core dumped)

$ perl -le'
$_ = ", " x 100_000;
s/,\s*(?=,)//g;
print;
'
,




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to