in reply to Reading and incrementing an integer
Indeed. You need to "rewind" the file to overwrite the prior value, and you need to increment the value before you print it. print HITSW $read_hits++; isn't doing what you think. I'm guessing that you had the value "1318" in your hit file at the time you changed to the code fragment you posted. By not reseting the file position before writing, and not incrementing the value, in effect you're appending "1318" onto the contents of the file, leading to a very long string of digits. You can test that by changing the file contents to "hi, mom\n" and seeing what happens.
Try making this change:
my $read_hits = <HITSW>; seek HITSW, 0, 0; print HITSW $read_hits + 1;
|
|---|