-
PERL or CGI help
Hi
i want a perl or cgi script to do this:
An html page will call it sending it a variable, then the script will open a file on the server named as the variable, it will read the number at the first line and decrese this number by one and save this file with it`s original name and if it is done correctly to return "OK".
Can somebody please help me????
Last edited by Axristos; 11-13-2003 at 02:48 PM.
Mess With The Best, Die Like The Rest...
-
The Definition of...
Take my script and modify it to your needs.
#!/usr/bin/perl
use CGI;
$query = new CGI;
$theFile = $query->param("theFile");
print "Content-type: text/html\n\n";
if (-e $theFile){
open(NUMBER, $theFile) || die "file could not be opened";
$number = <NUMBER>;
close(NUMBER);
}
else{
$number = "0";
}
$number++;
open(NUMBER,">$theFile") || die "file could not be opened";
print NUMBER "$number";
close(NUMBER) or die "Could not close $theFile";
print "Success=$number\n";
L. Jones
www.urbansory.com
-
I saw your code before post this topic but i don`t know many thing from cgi and i can`t understand almost anything. I can understand that "$theFile = $query->param("theFile");" is the variable from the explorer named "thefile", "open(NUMBER, $theFile)" this opens the file but why you need NUMBER?. "close(NUMBER);" closes the file opened before. Something else "$number++;" is outside of the open-close tag. How it saves that number?
Mess With The Best, Die Like The Rest...
-
The Definition of...
#!/usr/bin/perl
use CGI;
$query = new CGI;
//This takes the variable from flash named "theFile" and makes it into a variable for the PERL script
$theFile = $query->param("theFile");
print "Content-type: text/html\n\n";
//This checks to see if the file "theFile" is on the server. ( Say theFile = "counter.dat"
if (-e $theFile){
open(NUMBER, $theFile) || die "file could not be opened";
//This takes whatever is in counter.dat and turns it into a variable for the perl script called number
$number = <NUMBER>;
close(NUMBER);
}
else{
//If the file counter.dat does not exist, sets the variable number to "0"
$number = "0";
}
//Increments the variable number by 1
$number++;
//Opens the file counter.dat with writing privileges
open(NUMBER,">$theFile") || die "file could not be opened";
//Writes the value in the variable number to the file counter.dat
print NUMBER "$number";
close(NUMBER) or die "Could not close $theFile";
//This sends a variable called Success to Flash with the "OK"
print "Success="OK"\n";
So <NUMBER> is the opened file counter.dat
$number is a variable
L. Jones
www.urbansory.com
-
Can you please tell me how to call the cgi script sending it the variable (the name) of the window to open?
Because when i acll it it does nothing.
Mess With The Best, Die Like The Rest...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|