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. -
#!/usr/bin/perl
-
-
#use CGI::Carp qw(fatalsToBrowser);
-
-
#use strict;
-
-
use CGI;
-
-
use Tie::File;
-
-
$query = new CGI;
-
-
$data_file="nameList.cgi";
-
-
open(DAT, $data_file) || die("Could not open file!");
-
-
@raw_data=<DAT>;
-
-
tie @line, 'Tie::File', $data_file or die("Could not open file!");
-
-
print $query->header();
-
-
print "Content-type: text/html\n\n";
-
-
print "<HTML><HEAD>\n";
-
print "<TITLE>Thanks!</TITLE></HEAD>\n";
-
print "<BODY>";
-
-
$first = $query->param("first");
-
$last = $query->param("last");
-
$email = $query->param("email");
-
-
-
-
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";
-
-
-
-
$count = 0;
-
-
@WS = $query->param("ws");
-
-
foreach $ws(@WS){
-
-
$line[$ws-1].="$first $last, $email|";
-
-
}
-
-
close(DAT);
-
-
print "</BODY>\n";
-
-
print "</HTML>\n";
-
-------------------------------------------------------------------------------------------------------
And I've tried use warnings, add and remove -w.....doesn't work.........crying T-T
Cannot appreciate more.
20 2055
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
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. - use CGI::Carp qw(fatalsToBrowser);
-
use strict;
Then I would declare the variables correctly using my. What OS are you using?
You're not actually using Tie::File to do anything in the code you posted. Are you just experimenting?
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.
Sorry, I missed those lines.
Untested code: -
#!/usr/bin/perl
-
-
use CGI::Carp qw(fatalsToBrowser);
-
use strict;
-
use warnings;
-
use CGI;
-
use Tie::File;
-
use Fcntl;
-
-
my $query = new CGI;
-
print $query->header,$query->start_html('Thanks!');
-
-
my $data_file = "nameList.cgi";
-
-
tie my @line, 'Tie::File', $data_file, mode => O_RDWR or die "$!";
-
-
my $first = $query->param("first");
-
my $last = $query->param("last");
-
my $email = $query->param("email");
-
-
print $query->p(qq{$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.});
-
-
my @WS = $query->param("ws");
-
-
foreach my $ws (@WS){
-
$line[$ws-1].= "$first $last, $email|";
-
-
}
-
untie @line;
-
print $query->end_html;
-
KenvinADC, I will try it tomorrow when I go to the lab. Appreciate that :)
Hi KenvinADC, it seems like the code you modified for me still doesn't work.
Unless you can be more specific I can't help.
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 :)
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?
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.
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.
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.
The module is installed, but I still get another error. Can anyone help??? Than.........ks!!!
Error:
Premature end of script headers:
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.
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.
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.
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.
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.
Yeah, finally it works. Thank you so...................much, KevinADC.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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;...
|
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...
|
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,...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |