CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
HELP~~URGENT...Perl replacement!!

 



Adrian99420
New User

May 27, 2008, 11:57 PM

Post #1 of 4 (564 views)
HELP~~URGENT...Perl replacement!! Can't Post

Hi,

I am trying to replace string in another file. Here is what I wrote:

perl -pi -i.bak -e "s/MMSC/hello/" CustomizationView.cpp

I can replace the string in customizationview.cpp file, however, this method replace every match string in the file mentioned. I wish to replace only the first match string. How can I do this? What should I edit in my code? I knew there is other ways like regex to do this. However, I need only simple code to do this....Pls lend me some help...

Million thanks in advance!!



Adrian99420
New User

May 29, 2008, 2:24 AM

Post #2 of 4 (547 views)
Re: [Adrian99420] HELP~~URGENT...Perl replacement!! [In reply to] Can't Post

Hi,

I still unable to solve the problem, can any pro fren lend me a helping hand? I wish to replace only the first match string. Currently the perl command I used will replace all the match string in file I selected. Or what command should I use to start string replacement on certain line? For example here is what i have in my file:

hello.cpp

line1: Hi, My name is Adrian.

line2: I am 20 years old.

line3: My hobby is programming.



How can I replace the "is" in third line? Really need this in urgent!!

Million thanks in advance.


(This post was edited by Adrian99420 on May 29, 2008, 2:29 AM)


KevinR
Veteran


May 30, 2008, 12:30 PM

Post #3 of 4 (508 views)
Re: [Adrian99420] HELP~~URGENT...Perl replacement!! [In reply to] Can't Post

The reason I have not tried to answer your questions is because I almost always ignore anyone that posts "URGENT" and "HELP" and other such declarative nonsense to try and get fast help or attention. This is not tech support, and no question is anymore urgent than any other question to the people answering them, of which there are few on this forum. Keep that in mind for next time if there is a next time.
-------------------------------------------------


meloyelo
User

Jun 8, 2008, 6:37 PM

Post #4 of 4 (456 views)
Re: [Adrian99420] HELP~~URGENT...Perl replacement!! [In reply to] Can't Post

Try using Tie::File:


Code
use Tie::File; 

tie @lines, 'Tie::File', $filename;

$lines[2] =~ s/ is / ... /;

untie @lines;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives