How would I go about changing a specific line in a file? Or just deleting a line and re-printing one in the same spot?
Thanks!
--Edge
How would I go about changing a specific line in a file? Or just deleting a line and re-printing one in the same spot?
Thanks!
--Edge
Orpheus posted this at 20:58 — 16th September 2000.
They have: 568 posts
Joined: Nov 1999
$file = "something.txt";$line = 4;
open(file,$file);
@contents = <file>;
close(file);
$contents[$line] = "something new\n";
'
this will change line 4 of something.txt to the string "something new" and a line break at the end.
Edge posted this at 22:55 — 17th September 2000.
They have: 117 posts
Joined: Mar 2000
Your code changed the line after the one I wanted it to, so I had to add $line--; and then it worked. Thanks!!
--Edge
Mark Hensler posted this at 23:18 — 17th September 2000.
He has: 4,044 posts
Joined: Aug 2000
that's because arrays start with 0
so the first line would be $contents[0]
Orpheus posted this at 23:23 — 18th September 2000.
They have: 568 posts
Joined: Nov 1999
oh *smacks himself* forgot to mention that
and the fact that you need to re-write the array to the file your opening.