Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find, Increment and Replace Number @ Line?

Status
Not open for further replies.

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! :eek:)
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, &quot;+< test.txt&quot;) || &quot;Die Message!\n&quot;;
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. :eek:)
Cheers!
Marc - simracing_marc@yahoo.com
 
hi marc -- be lazy, just read in the whole file, modify the data on the last line in memory and then create the file again.

Mike
michael.j.lacey@ntlworld.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top