×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Find, Increment and Replace Number @ Line?

Find, Increment and Replace Number @ Line?

Find, Increment and Replace Number @ Line?

(OP)
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
http://joe.schmoe.com
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close