srhearts has asked for the wisdom of the Perl Monks concerning the following question:

I am new to this group so excude me if this post is in wrong place. I want to use perl script to search some strings inside the C source code and If i can find the targeted string then I want to replace that string with another string. But I don't know If I can do that or not using perl.But I am very hopeful. Please give me some suggations.

2006-03-24 Retitled by planetscape, as per Monastery guidelines
Original title: 'How to use Perl script inside a C code'

  • Comment on How to use Perl to search and replace inside C source code

Replies are listed 'Best First'.
Re: How to use Perl to search and replace inside C source code
by codeacrobat (Chaplain) on Mar 23, 2006 at 17:24 UTC
    This script should replace all oldstring to newstring in the file bla.c
    For safety reasons a backup bla.c~ is created.
    perl -pi~ -e 's/oldstring/newstring/g' bla.c