Guest_imported
New member
- Jan 1, 1970
- 0
Hi all,
I'm trying to solve a problem where I need to read a number from an existing list (variable is preset), at a particular line, increment by one, and then write back to the list. Specifically, I have a text description file for each downloadable ZIP file from my page. The text includes author name, description, etc., and I would like to reference a number in the last line of the file.
The list looks something like the following:
Win Paint Utility
Joe Schmoe
joe@schmoe.com
12/25/99
Here's a great file for to download. Features include 4-on-the-floor, chrome makeshifts, tele-tubbies and more!
)
Win95/98/NT
112
The last line is the number of downloads. The problem is, I've only been able to get the counter to work if:
1) It's at the begining of the file
2) Has trailing spaces (to prevent line-2 from jumping up)
I'm currently messing with the following code, as I found it to be a close match to what I need:
if (-w 'test.txt') {
open(COUNTER, "+< test.txt"
|| "Die Message!\n";
flock(COUNTER,2);
$count = <COUNTER>; #read the current value.
$count++;#increment it by one.
seek(COUNTER, 0, 0); #rewind the file.
print COUNTER $count; #write the new value to the file.
close COUNTER;
}
Any help would be most appreciated.
)
Cheers!
Marc - simracing_marc@yahoo.com
I'm trying to solve a problem where I need to read a number from an existing list (variable is preset), at a particular line, increment by one, and then write back to the list. Specifically, I have a text description file for each downloadable ZIP file from my page. The text includes author name, description, etc., and I would like to reference a number in the last line of the file.
The list looks something like the following:
Win Paint Utility
Joe Schmoe
joe@schmoe.com
12/25/99
Here's a great file for to download. Features include 4-on-the-floor, chrome makeshifts, tele-tubbies and more!
Win95/98/NT
112
The last line is the number of downloads. The problem is, I've only been able to get the counter to work if:
1) It's at the begining of the file
2) Has trailing spaces (to prevent line-2 from jumping up)
I'm currently messing with the following code, as I found it to be a close match to what I need:
if (-w 'test.txt') {
open(COUNTER, "+< test.txt"
flock(COUNTER,2);
$count = <COUNTER>; #read the current value.
$count++;#increment it by one.
seek(COUNTER, 0, 0); #rewind the file.
print COUNTER $count; #write the new value to the file.
close COUNTER;
}
Any help would be most appreciated.
Cheers!
Marc - simracing_marc@yahoo.com