Re: Help sought for search & replace

Re: Help sought for search & replace

am 29.01.2008 22:02:17 von someone

Anand Hariharan wrote:
> I would like to replace all occurrences of '/' by '\' -- but only
> those instances of '/' within that portion of a line between the first
> and second ':'.
>
> Example:
>
> C:/My/Source/Tree/Code.cpp:176: x = 2/3; // Some insightful comment
>
> becomes
>
> C:\My\Source\Tree\Code.cpp:176: x = 2/3; // Some insightful comment

perl -pe's{(:.+?:)}{($a=$1)=~y[/][\\];$a}e' yourfile


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

Re: Help sought for search & replace

am 31.01.2008 02:21:14 von someone

Anand Hariharan wrote:
> On Jan 29, 3:02 pm, "John W. Krahn" wrote:
>> Anand Hariharan wrote:
>>> I would like to replace all occurrences of '/' by '\' -- but only
>>> those instances of '/' within that portion of a line between the first
>>> and second ':'.
>>> Example:
>>> C:/My/Source/Tree/Code.cpp:176: x = 2/3; // Some insightful comment
>>> becomes
>>> C:\My\Source\Tree\Code.cpp:176: x = 2/3; // Some insightful comment
>> perl -pe's{(:.+?:)}{($a=$1)=~y[/][\\];$a}e' yourfile
>>
>
> Thanks, John. I like your perl one-liners that you post in c.u.s.
>
> Could you point me to the chapter in Programming Perl (or some other
> online reference) that explains the s{}{}e syntax?

http://perldoc.perl.org/perlop.html#s%2fPATTERN%2fREPLACEMEN T%2fmsixpogce

http://perldoc.perl.org/perlretut.html

http://perldoc.perl.org/perlre.html

Note that these pages cover Perl version 5.10.0 which you may not have
installed yet on your computer. If you do have Perl installed then you
should have the documentation installed as well which you can access
from the command line like so:

perldoc perlop

perldoc perlretut

perldoc perlre



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