Can I do this? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Can I do this?

Is it possible to write to a certain part of a file?



Example:



[data.dat]

1

2

3[4]

4



Can I open file data.dat and then change the 3 on the third row to a four?



Any help would be great. =D


Comments

  • : Is it possible to write to a certain part of a file?

    :

    : Example:

    :

    : [data.dat]

    : 1

    : 2

    : 3[4]

    : 4

    :

    : Can I open file data.dat and then change the 3 on the third row to a four?

    :

    : Any help would be great. =D

    :



    I suggest that you use a for-loop to read all lines from the file to an array. When the loop count reaches "3" (for third line) use regular expression techniques to replace the "3" with a "4". Then rewrite the file(use ">" in front of your filename when you open it e.g. open(FILE ">$filename")) And write all items from the array to the textfile.




  • Thank you! I tried this and it worked nicely =D (NT)


Sign In or Register to comment.