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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.