|
Hey, I am taking a class in perl, and my assignement was to make this form so i have the form all made and it works, now i have to take this form and have the data that is entered saved to a text file. how would i go about doing this. here is my perl file.
#!C:/Perl/bin/perl.exe
#juniper.cgi - creates a dynamic Web page that acknowledges
#the receipt of a registration form
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use strict;
#declare variables (** change $ to @ in sysletter / add $key **)
my ($name, $serial, $modnum, @sysletter, $key);
my @models = ("Laser JX", "Laser PL", "ColorPrint XL");
# add hash declaration
my %systems = ("W", "Windows",
"M", "Macintosh",
"L", "Linux");
#assign input items to variables
$name = param('Name');
$serial = param('Serial');
$modnum = param('Model');
# (** change $ to @ in sysletter)
@sysletter = param('System');
#create Web page
print "<html><head><title>Juniper Printers</title></head>\n";
print "<BODY><H2>\n";
print "Thank you, $name, for completing \n";
print "the registration form.<br /><br />\n";
print "We have registered your Juniper $models[$modnum] printer, \n";
print "serial number, $serial. \n";
# (** modify hash references for multiple selections **)
print "You indicated that the printer will be used on the \n";
print "following systems: <br /> \n";
foreach $key (@sysletter) {
print "$systems{$key} <br />\n";
}
print "</h2></body></html>\n";
if you need me to post my form file i can do that as well. thanks
|
|
|
|
|
I tried using this and i understand how it works, but where do i place each section of the code?? i have tried a few places and it doesnt work. any help is great thanks.
|
|
|
just put that filehandle thing at the end of the code.
And then you can print whatever vars you want into your new file.
|
|
|
im still having trouble, i put the coe at the very bottom and it is still not writing to the text file here is my code:
#!C:/Perl/bin/perl.exe
#juniper.cgi - creates a dynamic Web page that acknowledges
#the receipt of a registration form
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use strict;
#declare variables (** change $ to @ in sysletter / add $key **)
my ($name, $serial, $modnum, @sysletter, $key);
my @models = ("Laser JX", "Laser PL", "ColorPrint XL");
# add hash declaration
my %systems = ("W", "Windows",
"M", "Macintosh",
"L", "Linux");
#assign input items to variables
$name = param('Name');
$serial = param('Serial');
$modnum = param('Model');
# (** change $ to @ in sysletter)
@sysletter = param('System');
#create Web page
print "<html><head><title>Juniper Printers</title></head>\n";
print "<BODY><H2>\n";
print "Thank you, $name, for completing \n";
print "the registration form.<br /><br />\n";
print "We have registered your Juniper $models[$modnum] printer, \n";
print "serial number, $serial. \n";
# (** modify hash references for multiple selections **)
print "You indicated that the printer will be used on the \n";
print "following systems: <br /> \n";
foreach $key (@sysletter) {
print "$systems{$key} <br />\n";
}
print "</h2></body></html>\n";
open (W_FILE, "/forum/gtgtCInetpubwwwrootjunreg.txt");
print W_FILE "Hey, this text is going straight to the file.\n";
close W_FILE;
|
|
|
Try writing straight into c:
Maybe its something with the folder structure, like folder not existing, syntax wrong or something.
So try changing it into the following:
open (W_FILE, "/forum/gtgtCjunreg.txt");
print W_FILE "Hey, this text is going straight to the file.\n";
close W_FILE;
//now junreg.txt should be in the C:\
|
|
|
The file may be created in the folder in which you run the program.
|
|
|
I finally got it to work, thanks for your help
|
|
|
Your welcome, thanks for helping me make the guide better.
Mimir
|
|
|
|
|
|
|
// |