One more extension to this qn. #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; printf "word=$word#\n"; 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. word=DetailDesignActivityIncluded,NEW,,NEW,,-1,0,hello,ajey# ^^^ ^^^ These two are again not matched. I checked the options for c Do not reset search position on a failed match when /g is in effect. g Match globally, i.e., find all occurrences. i Do case-insensitive pattern matching. m Treat string as multiple lines. o Compile pattern only once. s Treat string as single line. x Use extended regular expressions. But, this is little confusing to me. I know its greedy approach while matching patterns,but here its missing something. Where am i wrong?? My aim to have a NEW inserted btwn every ,, Regards -Ajey On Sun, 17 Oct 2004, Gunnar Hjalmarsson wrote: > Ajey Kulkarni wrote: > > Gunnar Hjalmarsson wrote: > >> Ajey Kulkarni wrote: > >>> I would like to remove all the spaces & tabs from a variable. > >> > >> No, you wouldn't. You would like to remove possible whitespace from > >> the beginning and end of a string. > >> > >>> my($word) = " Detail Design Activity Included "; > >>> > >>> $word =~ s/^\s*(\D*)\s*$/$1/; > >> > >> It's best done using two substitutions: > >> > >> $word =~ s/^\s+//; > >> $word =~ s/\s+$//; > > > > Thanks a ton Gunnar, > > How about the intermediate blanks? Is there a way to recursively take > > all blanks/tabs that occur?? > > Did you really want that? In that case I misunderstood you; Please > disregard my previous suggestion. > > To actually remove *all* whitespace, you can simply do: > > $word =~ s/\s+//g; > > Read about the /g modifier in the description of the s/// operator in > "perldoc perlop". > > -- > 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> > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>