PERL script help
-
Hi, In a nut shell I'm trying to post some data to a file on a server, and I am having problems. Since this is a project from a college class that finished on Friday, I need some help to finish it before I forget what the assignment was about. It is somewhat goofy what we were doing, so I will leave most of what already works out of my story. We are supposed to take a file that is nothing but a text file and is a list of some data. The Perl/CGI file reads that data, constructs a web page that shows that data using a form and input tags. It also, using JavaScript, shows the data in a tree structure. All that code works great and is not my problem. We are supposed to use the same Perl/CGI file to update the text file on the server using a POST by saving to that text file any changes we make to our data. I can not get the post to work. I do not know if my form is the problem or the problem is in the Perl Script code that detects when I need to make the changes to the text file. I think it is in the form, but I am not sure what properties I need to declare in the form tag except for method="POST". I could include the code, but it is unnecessary to do so right now. If you could suggest a good tutorial on what you need to do to make a post using perl that would even be ok. I will post the code if nothing else is working for me. Thanks. PS - In other words, I don't want you to write my code, just explain to me what steps I need to take or guide me to the right solution. Thanks.
-
Hi, In a nut shell I'm trying to post some data to a file on a server, and I am having problems. Since this is a project from a college class that finished on Friday, I need some help to finish it before I forget what the assignment was about. It is somewhat goofy what we were doing, so I will leave most of what already works out of my story. We are supposed to take a file that is nothing but a text file and is a list of some data. The Perl/CGI file reads that data, constructs a web page that shows that data using a form and input tags. It also, using JavaScript, shows the data in a tree structure. All that code works great and is not my problem. We are supposed to use the same Perl/CGI file to update the text file on the server using a POST by saving to that text file any changes we make to our data. I can not get the post to work. I do not know if my form is the problem or the problem is in the Perl Script code that detects when I need to make the changes to the text file. I think it is in the form, but I am not sure what properties I need to declare in the form tag except for method="POST". I could include the code, but it is unnecessary to do so right now. If you could suggest a good tutorial on what you need to do to make a post using perl that would even be ok. I will post the code if nothing else is working for me. Thanks. PS - In other words, I don't want you to write my code, just explain to me what steps I need to take or guide me to the right solution. Thanks.
Additional--- I kept trying different things and I have now got everything to work except the file is appended data to the txet file. Here is the code I am using: open (myCourses, "+; I then manipulate the data and write it back to the same file inside a foreach loop using the @lines variable. What I get is a duplication of the existing data. I want the data to be removed from the file and then new data added back. The instructor said we are suppossed to use the open statement above, not a read and then a write. Should not this line behave the same as using an open read, and then an open write? I have tried everything, I think. Please help.
-
Additional--- I kept trying different things and I have now got everything to work except the file is appended data to the txet file. Here is the code I am using: open (myCourses, "+; I then manipulate the data and write it back to the same file inside a foreach loop using the @lines variable. What I get is a duplication of the existing data. I want the data to be removed from the file and then new data added back. The instructor said we are suppossed to use the open statement above, not a read and then a write. Should not this line behave the same as using an open read, and then an open write? I have tried everything, I think. Please help.
The code is: open (myCourses, "+<courses.txt") or die $!; my @lines = <myCourses>; Sorry for the mess up.
-
The code is: open (myCourses, "+<courses.txt") or die $!; my @lines = <myCourses>; Sorry for the mess up.
Not really sure if this will help you, perl docs - open "You can put a '+' in front of the '>' or '<' to indicate that you want both read and write access to the file; thus '+<;' is almost always preferred for read/write updates--the '+>;' mode would clobber the file first. You can't usually use either read-write mode for updating textfiles, since they have variable length records."