Both
Previous  Top  Next

Here we will read the content of a file (a number), increase the number, and write the new number to the same file:

01: open (WEBCOUNTER,"<webcounter.txt") || die "Cannot open file";
02: $webcounts = <WEBCOUNTER>;
03: close(WEBCOUNTER);
04: 
05: $webcounts++;
06:
07: open (WEBCOUNTER,">webcounter.txt") || die "Cannot open file";
08: print WEBCOUNTER $webcounts;
09: close(WEBCOUNTER);
10:
11: print "$webcounts since July 1903\n";

Yes, it is as simple as that. The variable $webcounts now holds the current web counts. Please note the differences in lines 1 (<), where we read from the file, and line 7, where we write to the file.