M
mukunthini
I'm new to Perl and am trying to get a simple counter script to work.
It seems to be able to read the counter.dat file ok but I can't get
it to write the new file count to the file. When im executing the
script in command line it's working well and updating the couner.dat
also to new value. but when im running the file in web browser it's
reading the counter value.The counter get's incremented just fine, But
I cannot get the thing to write back out to the counter.dat file with
the new value. My file permissions seem to be ok. It reads the
counter.dat file but will not write to it. and in the error log its
giving the following error
"hi.pl: Cannot open for writing: Permission denied at /var/www/cgi-
bin/hi.pl line 13."
im using Fedora linux, apache 2.0 and perl 5.6.2 .......and mozilla
firefox browser to execute this file
Anybody ever seen this happen?
here is the code:
#!/usr/local/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
print "Content-type: text/html\n\n"; # Web page as default output
open (COUNT, "counter.dat"); # Open for read using COUNT file
handle
$hitcount = <COUNT>; # Read in file to get current count
value
close COUNT; # Close the data file
$hitcount = $hitcount + 1; # Increment count value
open (COUNT, "> counter.dat") or warn "Cannot open $file for writing:
$!"; # Open data file for write
flock(COUNT, 2);
print COUNT "$hitcount"; # Write updated count value
close COUNT; # Close the data file
print "$hitcount"; # Display updated count on the page
exit;
thankx in advance.....!
regards
mukunthini
It seems to be able to read the counter.dat file ok but I can't get
it to write the new file count to the file. When im executing the
script in command line it's working well and updating the couner.dat
also to new value. but when im running the file in web browser it's
reading the counter value.The counter get's incremented just fine, But
I cannot get the thing to write back out to the counter.dat file with
the new value. My file permissions seem to be ok. It reads the
counter.dat file but will not write to it. and in the error log its
giving the following error
"hi.pl: Cannot open for writing: Permission denied at /var/www/cgi-
bin/hi.pl line 13."
im using Fedora linux, apache 2.0 and perl 5.6.2 .......and mozilla
firefox browser to execute this file
Anybody ever seen this happen?
here is the code:
#!/usr/local/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
print "Content-type: text/html\n\n"; # Web page as default output
open (COUNT, "counter.dat"); # Open for read using COUNT file
handle
$hitcount = <COUNT>; # Read in file to get current count
value
close COUNT; # Close the data file
$hitcount = $hitcount + 1; # Increment count value
open (COUNT, "> counter.dat") or warn "Cannot open $file for writing:
$!"; # Open data file for write
flock(COUNT, 2);
print COUNT "$hitcount"; # Write updated count value
close COUNT; # Close the data file
print "$hitcount"; # Display updated count on the page
exit;
thankx in advance.....!
regards
mukunthini