webdesignerX002
10-31-2003, 06:50 PM
I have tried everything and I can't seem to figure my problem out. I am trying to to save a text file using a scalar variable ($scalar). What I need the script to do is to open a different log file set the first line of the log to the scalar variable and then save the file name to that scalar variable.
Here is my script so far:
# Beginning of Script #
#! c:\Perl\bin\perl.exe -wT
use strict;
use CGI ':standard';
# Directory path that files will be uploaded into #
my $upload_dir = "/My Documents/Webpages/lawreview/logs/";
# Set the file name to be used for saving the upload infomation in #
my $datafile = "title.txt";
# Variable's to receive input from HTML Form #
my ($type, $number, $title, $file, $info, $MIMEType, $DIR_PATH, $FILE_NAME);
$type = param('Titletype');
$number = param('Title_Number');
$title = param('htmlText');
$file = param('uploadfile');
$info = uploadInfo($file);
$MIMEType = $info->{'Content-Type'};
# Retrieves Edition information from edition.txt file and stores it into an array #
open (LOGA, "<../lawreview/logs/edition.txt") || Error('open', 'file');
my @logmessage = <LOGA>;
close (LOGA);
#Grabs the first line on the logmessage array and saves it into $edition and then establishes filename scalar#
my $edition = $logmessage[0];
my $filename = "log$edition$type$number.txt";
# Opens text file to save title into, this is just to test dir and file name using scalar variables #
open (LOG, ">$upload_dir/$datafile") || Error('open', 'file');
print LOG "$title";
close (LOG) || Error('close', 'file');
# Establishes file using $filename and opens it and saves title into it #
open (LOGB, ">$upload_dir/$filename") || Error('open', 'file');
print LOGB "$title";
close (LOGB) || Error('close', 'file');
# Shows Information that was submitted #
print "The information you submitted was:";
print "<blockquote>";
print"
You Submitted an: $type";
print"
It is $type: # $number";
print"
The title of $type # $number is:</p>";
print"<blockquote>$title</blockquote>";
print"
The file that goes with that title is: $file";
print"</blockquote>";
print"
If the information isn't correct click backspace on the browser and re-submit the information";
# Sub Routine that is displayed if perl is unable to open or close a file #
sub Error {
print "Content-type: text/html\n\n";
print "The server can't $_[0] the $_[1] : $! \n";
exit;
}
# End of Script #
Thank you for those who take the time to help me with this.
Here is my script so far:
# Beginning of Script #
#! c:\Perl\bin\perl.exe -wT
use strict;
use CGI ':standard';
# Directory path that files will be uploaded into #
my $upload_dir = "/My Documents/Webpages/lawreview/logs/";
# Set the file name to be used for saving the upload infomation in #
my $datafile = "title.txt";
# Variable's to receive input from HTML Form #
my ($type, $number, $title, $file, $info, $MIMEType, $DIR_PATH, $FILE_NAME);
$type = param('Titletype');
$number = param('Title_Number');
$title = param('htmlText');
$file = param('uploadfile');
$info = uploadInfo($file);
$MIMEType = $info->{'Content-Type'};
# Retrieves Edition information from edition.txt file and stores it into an array #
open (LOGA, "<../lawreview/logs/edition.txt") || Error('open', 'file');
my @logmessage = <LOGA>;
close (LOGA);
#Grabs the first line on the logmessage array and saves it into $edition and then establishes filename scalar#
my $edition = $logmessage[0];
my $filename = "log$edition$type$number.txt";
# Opens text file to save title into, this is just to test dir and file name using scalar variables #
open (LOG, ">$upload_dir/$datafile") || Error('open', 'file');
print LOG "$title";
close (LOG) || Error('close', 'file');
# Establishes file using $filename and opens it and saves title into it #
open (LOGB, ">$upload_dir/$filename") || Error('open', 'file');
print LOGB "$title";
close (LOGB) || Error('close', 'file');
# Shows Information that was submitted #
print "The information you submitted was:";
print "<blockquote>";
print"
You Submitted an: $type";
print"
It is $type: # $number";
print"
The title of $type # $number is:</p>";
print"<blockquote>$title</blockquote>";
print"
The file that goes with that title is: $file";
print"</blockquote>";
print"
If the information isn't correct click backspace on the browser and re-submit the information";
# Sub Routine that is displayed if perl is unable to open or close a file #
sub Error {
print "Content-type: text/html\n\n";
print "The server can't $_[0] the $_[1] : $! \n";
exit;
}
# End of Script #
Thank you for those who take the time to help me with this.