in reply to Writing to a New File
The following code updates the count 'in place' using a regex. If the regex fails an initial count is generated.
use strict; use warnings; open FLASHCOUNT, '<', '/var/www/html/log/FLASHCOUNT.txt'; my $line = <FLASHCOUNT> || ''; close(FLASHCOUNT); $line = 'count = 1' unless $line =~ s/(\d+)/$1 + 1/e; open FLASHCOUNT, '>', '/var/www/html/log/FLASHCOUNT.txt'; print FLASHCOUNT $line; close FLASHCOUNT; print "Content-type: text/html\n\n"; print $line; print "</BODY>\n"; print "</HTML>";
Update: note ikegami's comment re race conditions.
|
|---|