#1 (permalink)  
Old 06-26-2006, 10:08 PM
Registered User
 
Join Date: Jun 2006
Posts: 1
Problem with writing file in perl

Hi,

I am new to perl cgi. I am trying to implement a counter but i am not being able to open the file for writing.

Below is my perl code.

I have chmod 777 both on the directory as well as the text file I want to update.

Every Time I run the program I get Error - could not open file. What am I doing wrong?

Thanks in advance
a newbie

#!/usr/bin/perl
$log_file = "counter/data.txt";
$hitcount=0;
print "Content-type: text/html\n\n"; # Web page as default output

open (COUNT, $log_file) or &error("could not open file"); # Open for read using COUNT file handle
$hitcount = <COUNT>; # Read in file to get current count value
close COUNT; # Close the data file
print $hitcount;

$hitcount = $hitcount + 1; # Increment count value

open (OUT, ">$log_file") or &error("Could not open file"); # Open data file for write
flock(OUT, 2); # Locks file
print OUT "$hitcount"; # Write updated count value
close OUT; # Close the data file
exit;

sub error
{
my($errmsg) = @_;
print "<h2>Error</h2>\n";
print "<p>$errmsg</p>\n";
print end_html;
exit;
}
Reply With Quote

  #2 (permalink)  
Old 06-27-2006, 09:17 AM
Till's Avatar
Administrator
 
Join Date: Jan 2002
Location: Berlin, Germany
Posts: 1,453
If the permissions are all set, check the path to your "counter file".
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
framespacing="0" problem solved cssiscool Programming and Scripting 4 06-14-2007 08:27 AM
Upload From URL - Perl curtiss Programming and Scripting 5 05-20-2006 09:50 AM
Passing Variables to an .asx file Jami Programming and Scripting 2 04-26-2006 05:38 PM
Creating a file and saving it locally - PHP curtiss Programming and Scripting 6 03-25-2006 12:26 PM
Returning Without Going "Back" in Perl? curtiss Programming and Scripting 5 01-30-2006 04:39 PM


All times are GMT -5. The time now is 06:49 AM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter