Click to See Complete Forum and Search --> : Confused
Mrclean78
03-22-2003, 10:46 AM
I am currently working on a site for a class project. I am accepting data through a simple HTML form and processing it through CGI. I want to save the output into an external file, but I have no idea how to get it there.
open (RESUME, ">./Good/$save.xml") || Error ('open', 'file');
print RESUME " ";
close (RESUME);
this is my call to write to the file, but in my print statement, I don't know how to get what I want. Any help or where to look would be greatly appreciated.
Thank you for your help.
Nedals
03-22-2003, 11:16 AM
Build you 'form' data into a string.
#using strict and CGI.pm module
my $itemA = $q->param('fieldnameA');
my $itemB = $q->param('fieldnameB');
my $data = "$itemA:$itemB"; # ':' as delimiter
open (RESUME, ">./Good/$save.xml") || Error ('open', 'file');
print RESUME "$data\n";
close (RESUME);
my $path = "<path-from-root>"; # no '.'
open (RESUME,">$path/$filename" || die 'Can't open $filename';
jeffmott
03-23-2003, 06:33 PM
no '.'What's wrong with using relative paths?
Nedals
03-23-2003, 08:08 PM
What's wrong with using relative paths?
Nothing! I just think that a program is easier to follow/modify/debug if the full path is used. Personal preference I guess.
Mrclean78
03-27-2003, 07:03 PM
Thank you fo the help
Mrclean78
03-29-2003, 10:39 AM
I tried the code that Nedals gave to me but I couldn't quite figure things out. I've attached the code I do have with all of my variables. I've also put a link to my form page if that helps any. Thank you.
Build you 'form' data into a string.
#using strict and CGI.pm module
my $itemA = $q->param('fieldnameA');
my $itemB = $q->param('fieldnameB');
my $data = "$itemA:$itemB"; # ':' as delimiter
#These three lines are what I had to start, without the "$data\n"
open (RESUME, ">./Good/$save.xml") || Error ('open', 'file');
print RESUME "$data\n";
close (RESUME);
my $path = "<path-from-root>"; # no '.'
open (RESUME,">$path/$filename" || die 'Can't open $filename';
Any advice on a good resource that goes into all of this? Any help is once again greatly appreciated.
Correct Page (http://cman.lakeland.cc.oh.us/~i2190a04/IT%20Positions.htm)
Nedals
03-29-2003, 06:27 PM
Here's what I see...
I use this to collect my form data.
use CGI;
my $q = new CGI;
$words = $q->param('EmpHist');
The way you have it may work, I simply don't know. Maybe you already know or Jeff can enlighten you on that.
use CGI ':standard';
$words = param('EmpHist');
The 'require... ' line I would put near the beginning (habit), just in case you should call a sub prior to the require.
The path to your 'subroutines.lib' and your '$save.XML' shoud be a UNIX-path not a web-path. AND forget the '.' :)
my $path = /home/.../.../; # What ever your path is.
require './subroutines.lib'; ---> require "$path1/subroutines.lib"; # double quotes
open (RESUME, ">./Good/$save.xml")... ---> open (RESUME, ">$path2/Good/$save.xml")...
These to path are probable different
I got a page 'not found' when I tried you form page!
Nedals
04-04-2003, 12:23 AM
Got your PM.
Did you get your script working? If not...
Is the the file '$first_$last.xml' being created where you expect it?
Is the mime() subroutine included? To check, you could add a print statement.
What I use is a little subroutine I call debug()
sub debug {
my ($testmsg) = @_;
print "Content-Type: text/html\n\n";
print "<html>\n<head></head>\n<body>\n$testmsg\n</body>\n</html>\n";
exit;
}
I insert this anywhere in my program to test for anything
ie: insert after....
#Connect last and first name for name of file to be saved
$save = $last . '_' . $first;
&debug($save);
to make sure $save is correct.
Mrclean78
04-05-2003, 11:36 AM
Thanks Nedals. Everything works now. I kept coding but forgot to declare my variables. Thanks again