#snippet to replace all the ,, with ,NEW, my($word) = " Detail Design Activity Included ,,,, ,-1,0 ,hello,ajey ";
$word =~ s/\s+//g; $word =~ s/,,/,NEW,/gc;
The /c modifier is redundant, which Perl would have told you if warnings had been enabled. :(
Please enable strictures and warnings, and have Perl help you prevent the basic mistakes!
printf "word=$word#\n";
Don't use printf() when it's not necessary. print() is sufficient.
after removing the blanks ,if there are any ",," i would like to insert a NEW word there.
So my regex, does this but its doing it partially.
It's doing it exactly as you tell it to do it.
word=DetailDesignActivityIncluded,NEW,,NEW,,-1,0,hello,ajey# ^^^ ^^^ These two are again not matched.
Do you want to insert NEW whereever there are two consecutive commas? In that case, a zero-width assertion might be what you want:
$word =~ s/,(?=,)/,NEW/g;
Read about "extended patterns" in "perldoc perlre".
I know its greedy approach while matching patterns,but here its missing something.
Greediness has nothing to do with it. (Greediness is explained in "perldoc perlre".)
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>