Reading and writing to a file

M

MJS

Hello All,

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.
 
T

Tad McClellan

MJS said:
I have to determine if a scalar
variable in file1


Huh? Files are "data", not "code".

Only "code" has variables in it.

Whatever you were trying to say there, you didn't say it correctly...

(without knowing its location)


If it is impossible to find it, then it is impossible to operate on it.

There must be _some_ way to determine where it is.

What way is that?

Is there some text that always comes before/after it?

Is it always on line N ?

At the end of a line?

If you show us an example of your data, and what part you want
to extract, then we can probably help you with that part.

If you don't, then we can't.

has a certain value
(say 10).

==


So my question is how to do this


I dunno. Your "this" is known only to you at this point...

and how to write at a certain
location in file1.


perldoc -q file

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?
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top