Re: Replace white space between ""

Serguei Trouchelle <[email protected]>
Newsgroups gmane.comp.lang.perl.active-perl
Message-ID <[email protected]>
Angelos Karageorgiou wrote:

>>> I need to replace white space between delemiter "". After looking for do
>>> this I need to tell I did not find the solution!
>>> $test='test "ROYALE JEWELLER"@omr12.test.com<mailto:"ROYALE
>>> JEWELLER"@omr12.networksolutionsemail.com>   test';
>>> And I would like have this in $test3 (look the space between royale and
>>> jeweller is gone):
>>> test "ROYALEJEWELLER"@omr12.networksolutionsemail.com  test

>> $test =~ s/(".*?")/ $_ = $1; s!\s!!g; $_; /gex;

> Duh , please elaborate , it is edifying :-)

/e switch in s/// commands to treat replacement part as Perl expression. So, any Perl code can be there, and returning 
value will be used to replace matching pattern. So, technically, it's just nested s/// , but you can do pretty anything.

For example, s/(\d+)/sqrt($1)/gex changes any number to its square root.

perldoc perlop has some examples of how s/// can be used.

-- 
Serguei Trouchelle
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.