Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Search and Replace

6 views
Skip to first unread message

David Groff

unread,
Oct 8, 2008, 10:34:42 AM10/8/08
to
#I want to search and replace the text for all files within a directory.

#I am using opendir to put all the files in the array @datafiles.
#Then I use foreach to loop over all the files.

foreach $file (@datafiles){

#Here is how I read the file.

OPEN FILE, "+>", $file

#When I print to the terminal nothing happens

print FILE
CLOSE(FILE)

# What am I forgetting?


#What is a better way in perl to read the contents
#of the files and perform a search/replace using regular expressions.
#Is it better to read the entire file or one line at a time.

#By saying "better" I mean which method is less likely to result in some
#kind of mistake. Any opinions are appreciated.

So, in summary I have two questions
1. What am I forgetting when using perl to read in ascii files?
2. Is there a preferred method for performing a search and replace
on a file?


Thanks in advance for any insight.


0 new messages