473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How To write the content in a different file (i.e temp file)and then rename it to th

I have the following code, I need to write the content of a file.txt after searching

for line Local=IN, if found then its o.k if not found then enter the line Local=IN after

the line 'Testing Option OK'.

1. open FH, "<file.txt";
2. $/=undef; #set slurp mode
3. $file_contents=<FH>;
4. if (index($file_contents, "Local=IN")!=-1) { # file doesn't contain string
5. ($first, $second)=split(/Testion Option OK/, $file_contents);
6. $new_file=$first."\nTestion Option OK\nLocal=In\n".$second;
7.# write out the new file here
8. }
9. close FH;
Aug 22 '10 #1
1 1258
RonB
589 Expert Mod 512MB
Do you understand what that code is doing?

What did Axweildr say when you asked him to explain the code he gave you?

Do you know how to open a file and write to it?
Aug 22 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Amy G | last post by:
I am looking to make this code a little "nicer"... any suggestions??? I want to do a "read+" where I would be able to first read the contents of the file... then either close the file out or write...
1
by: Vikram | last post by:
I have suddenly started getting this errorin all my ASP.NET applications when I try to open any aspx page. Compiler Error Message: CS0016: Could not write to output file...
0
by: IKdev | last post by:
Hi all, I have win2003 server and NET 1.1 framework. Created simple ASP .NET app with one page that has button and a label. When trying to run got the CS0016 error (see below). My temp env....
3
by: broli85 | last post by:
I am writing an extension for Firefox 1.5. I would like to know if there is a way to write and read data to and from a file which is in the location of the extension (or somewhere in the user's...
0
by: Ramkumars19 | last post by:
Hi Friends, I'm trying to write an XML file, Data's from Dataset. I did some coding also, its giving me an error like "Access to this path is denied". Below i have given that code please help me...
2
kamill
by: kamill | last post by:
i need to write content of one text file into another text file. My code is working ,if i choose both files from same directory where my program reside..BUT,its not working if i select files from...
5
by: JonathanB | last post by:
Ok, so this is the scenario. I need to create a simple, no-frills XML editor for non-technical users. It doesn't have to do anything fancy, what I want is a series of text boxes with the text...
16
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good)...
1
by: pauld | last post by:
Hello - I have created a simple web application in VS 2005/ASP.net 2.0 for a university department to track problems with a new website that I have built for them. The app consists of an Access...
1
kirubagari
by: kirubagari | last post by:
Im having issue whereby i have to filter out the data and stored in abnormal log file.my code as below and i have attach the file to give the clearer picture of the scenario.I need to filter the data...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.