Read / write to files

M

MJS

I am new to perl and I need some help with the following problem.

I have two files viz. file1 and file2. I have to determine if a scalar
variable in file1 (without knowing its location) has a certain value
(say 10). If its true, then I have to add file2 to file1 at a certain
location.

So my question is how to do this and how to write at a certain
location in file1.

I would highly appreciate your help.

Thanks in anticipation.
 
J

Jürgen Exner

MJS said:
I have two files viz. file1 and file2. I have to determine if a scalar
variable in file1 (without knowing its location) has a certain value
(say 10).

Not enough information.
You would use open() and read() or maybe while (<FILEDESCRIPTOR>) to read
the file.
However we don't know what your file format and/or data format is, therefore
it is impossible to suggest any method for parsing the file.
If its true, then I have to add file2 to file1 at a certain
location.

Unclear what you mean. I know how to add two numbers, that we learn in
school. But
I have no idea what you mean by "add file2 to file1". Do you mean inserting
the content of file2 into file1? Do you mean inserting the file name of
file2 in file1? Do you want to overwrite the existing information (unlikely
because you said 'add')?

In any case, maybe the FAQ is of some help:
"How do I change one line in a file/delete a line in a file/insert a
line in the middle of a file/append to the beginning of a file?"
So my question is how to do this and how to write at a certain
location in file1.

You would use seek()

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top