Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file isn't being written to...should incredment by 1 w/ conditions met

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
if ($url eq 'visanet') {

if ($page eq 'uk') {
my $countfile = " open (COUNT, $countfile);
my $counter = <COUNT>;
close (COUNT);
open (COUNT, &quot;>$countfile&quot;);
my $counter += 1;
print COUNT $counter;
close (COUNT);
}

else {
my $countfile = &quot; open (COUNT, $countfile);
my $counter = <COUNT>;
close (COUNT);
open (COUNT, &quot;>$countfile&quot;);
my $counter += 1;
print COUNT $counter;
close (COUNT);
}

}


i changed my permissions to 'write' for visitors. nothing happens. no errors on the code.

help please... - spewn
 
Hi,

You might try using a full path statement to your count file instead of a relative path of you web home directory. Also, if you put the count file in the same directory as your cgi-bin script, you could just refer to the count file by name without a path.

Once you have a path that is not relative to your home directory, run the script from a command line to see if it works. You can artifically supply the url$ and other string until you have it working from the command line. Once its running properly from the command line, remove the artifically supplied strings and try it with the web server.

Leland Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
I think the problem is that you used 'my' with $counter twice. I think that saying my $counter += 1 will overwrite the previous value, giving the variable just a value of 1.
 
Hi,

I placed the my statement in my counter script and I got the following error.

Can't call method &quot;My&quot; without a package or object reference

I agree with Grahf that you should try the script with it.

Leland Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
Hi,

Try this from your command line (e.g. perl test.pl) When you have it working adjust it to work in your web page.

print (&quot;Content-type: text/html\n\n&quot;);

$url=&quot;visanet&quot;;
$page=&quot;uk&quot;;

if ($url eq 'visanet') {
if ($page eq 'uk') {
$countfile = &quot;visanetuk.dat&quot;;
open (COUNTER, &quot;$countfile&quot;);
$count = <COUNTER>;
chop ($count) if $count =~ /\n$/;
close (COUNTER);
$count += 1;
open (COUNTER, &quot;>$countfile&quot;);
print COUNTER (&quot;$count&quot;);
close (COUNTER);
print (&quot;$count&quot;);
}

else {
$countfile = &quot;visanet.dat&quot;;
open (COUNTER, &quot;$countfile&quot;);
$count = <COUNTER>;
chop ($count) if $count =~ /\n$/;
close (COUNTER);
$count += 1;
open (COUNTER, &quot;>$countfile&quot;);
print COUNTER (&quot;$count&quot;);
close (COUNTER);
print (&quot;$count&quot;);
}
}


Leland

P.S.

If you are running Linux or UNIX you will need a sheabang line something like the following as the first line of the script.

#!/usr/bin/perl

This above script line tell where your binary perl program lives

Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
Unless you have redefined the 'open' function, it will not open an URL.

The file you are trying to read and then write to MUST exist on a file system that the host can see 'locally'. If you are REALLY trying to modify a file on another remote server, then you will have to put something on the other server to facilitate that behavior. If the file is on a local file system, then give the 'open' function a valid path to that file. It can be either an absolute or relative path. If the file is in the same dir as your cgi code, then....

Code:
# open a local file
open(FILE,&quot;<./visanetuk.dat&quot;);
my $count = <FILE>;
close FILE;

# increment the count
$count++;

# open the file to print
open(FILE,&quot;>./visanetuk.dat&quot;);
print FILE &quot;$count\n&quot;;
close FILE;

HTH If you are new to Tek-Tips, please use descriptive titles, check the FAQs,
and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top