School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 306,966 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,848 people online right now. Registration is fast and FREE... Join Now!




search and replace in perl

 

search and replace in perl

mona_mrtzvi

5 Nov, 2009 - 08:56 PM
Post #1

New D.I.C Head
*

Joined: 1 Nov, 2009
Posts: 11

Hi everybody, I had a plan to use "Dev C++", but my friends suggested, PERL is much more efficinet in my case.
My code has to open a directory(only text files exist on this directory). Read every text file, and looks for specific number like (E122), and replace it with something elso, or leave it blank. Then this output of each file saves in a new textfile, and new directory. Till now, I can make a directory in perl. I can see all the contents of a directory, even in the share-folder in interanet. Also I can make a copy of file to another directory with the same name, or even specific name. Please see these codes. Still I couldn't combine all code together.
CODE

...my first code it shows the content f every directory
opendir(DIRHANDLE, "C:/Users/mona&jasmin/Desktop/pclaw1");
while (defined ($filename = readdir(DIRHANDLE))){
print "Inside pclaw1 is something called $filename\n";
}
closedir(DIRHANDLE);

......My second code.....copy file to new directory
use File::Copy;
copy("C:/Users/mona&jasmin/Desktop/pclaw1/pclaw.txt","C:/Users/mona&jasmin/Desktop/test");



please help me in searching for specific nmber in a textfile in the given directory, and replacing this number with something else. I used the command below, but It doesn't work in my case.Gives error

perl -p -i -e 's/oldstring/newstring/g' *


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 04:36AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month