Results 1 to 2 of 2
Jun 17, 2001, 03:37 #1
Open, edit and save a file all at once
I use the following code in PERL to open, edit and save a file all at once.
open (FILE, "+<counter.txt"); flock(FILE, 2); $number = <FILE>; $number = $number + 1; seek (FILE, 0, 0); truncate (FILE, 0); print FILE $number; close(FILE);
Jun 17, 2001, 06:07 #2
- Join Date
- Jun 2000
- Sydney, Australia
- 0 Post(s)
- 0 Thread(s)
Hi, I don't know Perl but it appears that code is opening, reading, truncating, writing then closing right?
$filename = "whatever.txt";
$file = fopen($filename, "r+");
$number = fread ($file, filesize ($filename));