473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

tie::File 500 Internal Server Error???

35
Hi folks,

Perl is always killing me. I always do it on my computer first and then upload to the server in our lab. And oh my, never ever be correct to run on the lab. This time I got the internal error. I tried to add and delete multiple lines and found out that is possibly due to tie::File.

Could you please help me to solve the problem? I am dying for it :(

Here's the code.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl 
  2.  
  3. #use CGI::Carp qw(fatalsToBrowser); 
  4.  
  5. #use strict; 
  6.  
  7. use CGI; 
  8.  
  9. use Tie::File; 
  10.  
  11. $query = new CGI; 
  12.  
  13. $data_file="nameList.cgi"; 
  14.  
  15. open(DAT, $data_file) || die("Could not open file!"); 
  16.  
  17. @raw_data=<DAT>; 
  18.  
  19. tie @line, 'Tie::File', $data_file or die("Could not open file!"); 
  20.  
  21. print $query->header(); 
  22.  
  23. print "Content-type: text/html\n\n"; 
  24.  
  25. print "<HTML><HEAD>\n"; 
  26. print "<TITLE>Thanks!</TITLE></HEAD>\n"; 
  27. print "<BODY>"; 
  28.  
  29. $first = $query->param("first"); 
  30. $last = $query->param("last"); 
  31. $email = $query->param("email"); 
  32.  
  33.  
  34.  
  35. print "<P>$first $last, thank you for signing up! Please click <a href=\"list.pl\">here</a> to see the signup table for confirmation and don't repeatly signing up.</P>\n"; 
  36.  
  37.  
  38.  
  39. $count = 0; 
  40.  
  41. @WS = $query->param("ws"); 
  42.  
  43. foreach $ws(@WS){ 
  44.  
  45. $line[$ws-1].="$first $last, $email|"; 
  46.  
  47.  
  48. close(DAT); 
  49.  
  50. print "</BODY>\n"; 
  51.  
  52. print "</HTML>\n"; 
  53.  
-------------------------------------------------------------------------------------------------------

And I've tried use warnings, add and remove -w.....doesn't work.........crying T-T

Cannot appreciate more.
Oct 25 '07 #1
20 2055
eWish
971 Expert 512MB
Welcome to TSDN Casybay!

You have posted code into the forum without using proper code tags. It is best practice here on TSDN to wrap all code posted into the forum in code tags.

Code tags start with [code] and end with [/code]. If you need an example other than this one, the please refer to the REPLY GUIDELINES (or POSTING GUIDELINES if you are starting a discussion) to the right of the Message window. You will find the examples and suggestions for posting there.

In addition, you can also add the language to your code tags. Here is an example:

[code=perl]
<some code>
[/code]

Please know that I have fixed your posts above to include the proper code tags. Please be sure and use code tags in all of your future posts here on TSDN.

- Moderator
Oct 25 '07 #2
eWish
971 Expert 512MB
What errors did you get? Did you check the error logs to see what was logged? I would uncomment the following lines and add use warnings; as well.
Expand|Select|Wrap|Line Numbers
  1. use CGI::Carp qw(fatalsToBrowser); 
  2. use strict;
Then I would declare the variables correctly using my. What OS are you using?
Oct 25 '07 #3
KevinADC
4,059 Expert 2GB
You're not actually using Tie::File to do anything in the code you posted. Are you just experimenting?
Oct 25 '07 #4
casybay
35
To eWish, sorry for that. I didn't notice that. I am using Windos XP in my computer and the lab's server OS is Linux, and for both of them, I am using Apache.
To KenvinADC, yes, I did. Please see line 44. I am going to write something to the file as my understand.
Thank you so much for you guys' replies.
Oct 25 '07 #5
KevinADC
4,059 Expert 2GB
Sorry, I missed those lines.

Untested code:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl 
  2.  
  3. use CGI::Carp qw(fatalsToBrowser); 
  4. use strict; 
  5. use warnings;
  6. use CGI; 
  7. use Tie::File;
  8. use Fcntl; 
  9.  
  10. my $query = new CGI; 
  11. print $query->header,$query->start_html('Thanks!');
  12.  
  13. my $data_file = "nameList.cgi"; 
  14.  
  15. tie my @line, 'Tie::File', $data_file, mode => O_RDWR or die "$!";
  16.  
  17. my $first = $query->param("first"); 
  18. my $last  = $query->param("last"); 
  19. my $email = $query->param("email"); 
  20.  
  21. print $query->p(qq{$first $last, thank you for signing up! Please click
  22.                 <a href="list.pl">here</a> to see the signup table for
  23.                 confirmation and don't repeatly signing up.}); 
  24.  
  25. my @WS = $query->param("ws"); 
  26.  
  27. foreach my $ws (@WS){
  28.    $line[$ws-1].= "$first $last, $email|"; 
  29.  
  30. untie @line;
  31. print $query->end_html;
  32.  
Oct 25 '07 #6
casybay
35
KenvinADC, I will try it tomorrow when I go to the lab. Appreciate that :)
Oct 25 '07 #7
casybay
35
Hi KenvinADC, it seems like the code you modified for me still doesn't work.
Oct 25 '07 #8
KevinADC
4,059 Expert 2GB
Unless you can be more specific I can't help.
Oct 25 '07 #9
casybay
35
Sorry for that KevinADC, cuz I am waiting for my permission to access to the error log, so before that, I cannot tell you more specific about the error.
Since there's something wrong with tie::File, could anyone inspire me what could possibly cause error with this function? Or is there anyother way to read and write a line from and to a file using perl?
Appreciate :)
Oct 25 '07 #10
KevinADC
4,059 Expert 2GB
I don't think the problem is with Tie::File. If you are running the script via a web server and getting a 500 internal server error the script may not even be compiling. Could be the path to perl is wrong or the scripts permissions are wrong or you uploaded the script in binary mode instead of text mode. If the problem was with Tie::File the CGI::Carp module should be printing an error to the screen. Any idea what version of perl you are using? Can you get any CGI scripts to work?
Oct 25 '07 #11
casybay
35
Yes, I can run other perl script which doesn't have that tie::File.
And I finally get my error log, here is the related error:

Can't locate Tie/File.pm in @INC (@INC contains: /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503 /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at /spare/WWW/cgi-bin/list.pl line 5.
BEGIN failed--compilation aborted at /spare/WWW/cgi-bin/list.pl line 5.
Oct 25 '07 #12
KevinADC
4,059 Expert 2GB
The problem is you are running a very old version of perl. Tie::File is not installed. I do not know if it will even work with such an old version of perl (5.005) . That mst be at least 10 years old. So for know you can't use Tie::File.
Oct 25 '07 #13
casybay
35
10 years old??? Oh my, yea....I searched on internet, saying that I missed a module, and I can add it to the makefile.pl. Hum....then I should let the website adminstrator to fix up that first. Thank you so much.
Oct 26 '07 #14
casybay
35
The module is installed, but I still get another error. Can anyone help??? Than.........ks!!!
Error:
Premature end of script headers:
Oct 26 '07 #15
KevinADC
4,059 Expert 2GB
The script I posted for you should not generate that error message unless the path to perl is wrong or you uploaded the script in binary mode instead of text mode. It looks like Tie::File will work with perl 5.005.
Oct 26 '07 #16
casybay
35
KevinADC, yes, I did use WS_FTP32 binary mode to upload the file, but seems other pl files are ok, only the file I am working on has problem T_T And this FTP program has twp options: ASCII and binary.
Oct 30 '07 #17
KevinADC
4,059 Expert 2GB
Try uploading in ASCII mode which is text mode. If that does not work, I am not sure what the problem is unless the path to perl is wrong.
Oct 30 '07 #18
casybay
35
I tried, and it is wierd. When I upload it in binary mode, I got the errror"premature end of script headers". And when I uploaded it in ASCII mode, I got "Can't locate warnings.pm in @INC " again. But our web administrator had already install the Tie module. Oh, my, this seems like endless. I really really appreciate your help, KevinADC.
Oct 30 '07 #19
KevinADC
4,059 Expert 2GB
The problem has to be the very old version of perl you are using. You are trying to write modern code using an outdated version of perl. Evidently the warnings pragma is not included with that version of perl:

use warnings;

remove that and use the -w switch on the shebang line:

#!/usr/bin/perl -w

but the best solution is use a newer version of perl. You will continue to have problems and you will just get frustrated. Ask the tech guys to upgrade perl if at all possible.
Oct 30 '07 #20
casybay
35
Yeah, finally it works. Thank you so...................much, KevinADC.
Oct 31 '07 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jonathan Weekes | last post by:
Being utterly a non Perl IT guy, I have to write a Perl script for a web site to edit a line in a file. I have looked on Google and found Tie to be what I needed, but I am really lost in how to...
1
by: SpecialK | last post by:
Does anyone know how to tie a large file to a hash without using shared memory? I know I can use Tie::File to tie the file to an array and from the array create a hash, but I need something that...
2
by: steventhrasher42 | last post by:
I very likely may be missing something here, but what stops a user from holding down the F5 key in their browser and generating hundreds of requests to IIS and thus tying up server resources? If...
2
by: kelly | last post by:
Hi, I don't have a code to show you, what I need are references or algorithms so that I'm in a right track. By the way, thanks for introducing me the array or arrays. Now I can continue my...
5
by: mich dobelman | last post by:
I am developing a web crawler which collects info from more than 50,0000 pages. but i am afraid this is going to clog the rental web server if I run it every single day. Is it possible to stop...
1
by: jonathan184 | last post by:
trying to rename filenames and extensions then add a header in line1 of each file if the header existed in line 1 to go to the next file. but i am getting error explciti errors Here is my...
1
by: J. J. Ramsey | last post by:
In Perl, there is a module called "Tie::File". What it does is tie a list to each line of a file. Change the list, and the file is automatically changed, and on top of this, only the bits of the...
2
by: eMko | last post by:
Hello, In Perl, using a Tie::File module I can easily and comfortably delete a line from the middle of a text file: my @file; open(DATA, "+<:encoding(utf8):raw" , "file.txt") or return 0;...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.