Directory specification in simple CGI program
by Tiradientes - 2/10/10 9:59 PM
My cgi is in a directory called "bin". I want it to point to directory "Count" which is located here:
. . bin
. . data
Count
. . htdocs
I gather that it means rewriting the line
open(A, "<$ab[1]");
but I am not sure how to do this. The full script is at the end of this message. I hope someone cal be of assistance.
--------------------------------------
FULL SCRIPT
--------------------------------------
#!/usr/local/bin/perl
# Change the line abve to match the path to perl on your server
#=========================================
# Copyright July 2002 All Rights Reserved
# By Brent Maurer.
#=========================================
# DON'T CHANGE ANYTHING AFTER THIS LINE
#=========================================
# INSTRUCTIONS FOR USE
# See accompanying README.TXT file.
use CGI;
$Arguments = $ENV{'QUERY_STRING'};
$LOCK_EX = 2;
$LOCK_UN = 8;
#print "Content-type: text/html\n\n";
print "Content-type: application/x-javascript\n";
print "Pragma: no-cache\n\n";
@ab = split(/=/, $Arguments);
$value=0;
unless (open(A, $ab[1]))
{
print "document.write(\'err\')\;";
die ("File not found $ab[1]");
}
close(A);
open(A, "<$ab[1]");
$value = <A>;
chomp($value);
$value += 1;
if ($value < $ab[0]) { $value = $ab[0]; }
#--------------------------------------------------------------------
sub comify{
my $text = reverse $_[0];
$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scalar reverse $text;
}
#-----------------------------------------------------------
my $val = comify($value);
print "document.write(\'$val\')\;";
close(A);
open(A, ">$ab[1]");
flock (A, $LOCK_EX);
print A $value;
flock (A, $LOCK_UN);
close(A);

Moderator
CNET Staff
Samsung Staff
Dell Staff