By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,906 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,906 IT Pros & Developers. It's quick & easy.

"require" problem?

P: n/a
Guten Morgen,
I am implementing a script that my client wants on their website. Within
the script there are several "require" statements. Any time one of these
"require" statements is executed, the script terminates.

Any ideas how I might solve this problem?
Cheers!
Jul 19 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Michael wrote:
I am implementing a script that my client wants on their website.
Within the script there are several "require" statements. Any time
one of these "require" statements is executed, the script
terminates.

Any ideas how I might solve this problem?


How about installing the modules that it tries to require? Just a thought.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2

P: n/a
On Thu, 18 Mar 2004 13:40:10 +0000, Gunnar Hjalmarsson wrote:
Michael wrote:
I am implementing a script that my client wants on their website.
Within the script there are several "require" statements. Any time
one of these "require" statements is executed, the script
terminates.

Any ideas how I might solve this problem?


How about installing the modules that it tries to require? Just a thought.


The files are installed just where I believe they need to be. Here is the
code that is giving me the problem:

&require_supporting_libraries
(__FILE__, __LINE__,
"$path/file1.cfg",
"$path/file2.cfg",
"$path/library/file3.pl",
"$path/html/file4.pl",
"$path/library/file5.pl");

sub require_supporting_libraries
{
local ($file, $line, @require_files) = @_; local ($require_file);

foreach $require_file (@require_files)
{
if (-e "$require_file" && -r "$require_file")
{
print "$require_file <br><br>";
require '$require_file';
}
}
}
When I run the code the path and name of the first file is printed to the
browser window. Only the first file is listed. If I comment out the
require statement, all of the files are listed. Clearly the code is
finding the files (as it makes it into the if code block) but when the
require statement is executed, the code terminates.

rats.

Is there a problem with the syntax of the require statement? Or maybe the
permissions of the files needs to be different?

Any ideas will be appreciated.
Cheers!
Jul 19 '05 #3

P: n/a
Michael wrote:

require '$require_file';
<snip>
Is there a problem with the syntax of the require statement?
Yes, it tries to require a file *literally* named '$require_file'.
Remove those quotes:

require $require_file;
Or maybe the permissions of the files needs to be different?


It seems to be checking for that.

You posted a piece of buggy code written for a several years old Perl
generation (Perl 4). You may want to advise your client to use a
modern quality script instead.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #4

P: n/a
On Fri, 19 Mar 2004 06:59:07 +0000, Gunnar Hjalmarsson wrote:
Michael wrote:

require '$require_file';


<snip>
Is there a problem with the syntax of the require statement?


Yes, it tries to require a file *literally* named '$require_file'.
Remove those quotes:

require $require_file;
Or maybe the permissions of the files needs to be different?


It seems to be checking for that.

You posted a piece of buggy code written for a several years old Perl
generation (Perl 4). You may want to advise your client to use a
modern quality script instead.


The code originaly did not have the quotes around $require_file. Without
the quotes the code would terminate with an error message "Internal Server
Error". So I added them to try and fix the problem, but seem to have
created another.

rats.

Jul 19 '05 #5

P: n/a
Michael wrote:
[...]
Without the quotes the code would terminate with an error message
"Internal Server Error".


This is not a Perl (or perl) error message. Check the server logs for the
real error message.

jue
Jul 19 '05 #6

P: n/a
Michael wrote:
Gunnar Hjalmarsson wrote:
Michael wrote:
Is there a problem with the syntax of the require statement?


Yes, it tries to require a file *literally* named
'$require_file'. Remove those quotes:

require $require_file;


The code originaly did not have the quotes around $require_file.
Without the quotes the code would terminate with an error message
"Internal Server Error". So I added them to try and fix the
problem, but seem to have created another.


You are obviously running the script as a CGI script, which it would
have been appropriate to let us know about in your initial message.

To have the browser display a more meaningful error message, you can
add this line somewhere at the beginning of the script:

use CGI::Carp 'fatalsToBrowser';

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #7

P: n/a
On Fri, 19 Mar 2004 06:59:07 +0000, Gunnar Hjalmarsson wrote:
You posted a piece of buggy code written for a several years old Perl
generation (Perl 4). You may want to advise your client to use a
modern quality script instead.

Hmm. Well, that might be a good idea. I typically perfer to write
my own code, but the client insists on the one that he has purchased a few
years ago and used successfully on a previous server.
What if I replaced that mess of code with:

use '$path/file1.cfg';
use '$path/file2.cfg';
use '$path/library/file3.pl';
use '$path/html/file4.pl';
use '$path/library/file5.pl';

Given that I have read that

use somemodule();

is equivalent to:

BEGIN {require somemodule}
I figure that an attempt to make this code work will be less time than
rewriting it.
Jul 19 '05 #8

P: n/a
Michael wrote:
On Fri, 19 Mar 2004 06:59:07 +0000, Gunnar Hjalmarsson wrote:
You posted a piece of buggy code written for a several years old
Perl generation (Perl 4). You may want to advise your client to
use a modern quality script instead.
Hmm. Well, that might be a good idea. I typically perfer to write
my own code, but the client insists on the one that he has
purchased a few years ago and used successfully on a previous
server.

What if I replaced that mess of code with:

use '$path/file1.cfg';
use '$path/file2.cfg';
use '$path/library/file3.pl';
use '$path/html/file4.pl';
use '$path/library/file5.pl';


What happened when you tried it?

Honestly, if you are writing scripts for a client, you should know the
answer to that, or you should at least be able to figure it out
without asking here.

If you don't have access to the server's error log, did you try my
advice to load the CGI::Carp module and import the 'fatalsToBrowser'
routine?
Given that I have read that

use somemodule();

is equivalent to:

BEGIN {require somemodule}


That's only partly true, and not relevant here, since the files you
are trying to load aren't modules, i.e. they are not *.pm files.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #9

P: n/a
Gunnar Hjalmarsson wrote:
Michael wrote:
require $require_file;


The code originaly did not have the quotes around $require_file.
Without the quotes the code would terminate with an error message
"Internal Server Error". So I added them to try and fix the
problem, but seem to have created another.


You are obviously running the script as a CGI script, which it would
have been appropriate to let us know about in your initial message.

To have the browser display a more meaningful error message, you can
add this line somewhere at the beginning of the script:

use CGI::Carp 'fatalsToBrowser';


In addition to the above advice, make sure that each of your
require files ends with

1;

so that perl will recognize that the file was included successully.
-Joe
Jul 19 '05 #10

P: n/a
On Sat, 20 Mar 2004 22:10:09 +0000, Gunnar Hjalmarsson wrote:
If you don't have access to the server's error log, did you try my
advice to load the CGI::Carp module and import the 'fatalsToBrowser'
routine?

I tried it. With "require '$require_file';" I receive the following
error message:

http://bfr.caseywest.com/archives/001059.html

With "require $require_file;" the script terminates without any output.
I have checked to make sure that the directory where the files are, are in
@ic. I added the directory with "use lib". I then have a "print @INC;"
statement that outputs all of the directories in @INC and it does print
the one where the files I need are. However, when I use the second
version of the $require statement (the one without single quotes) there is
no output from the script.
Cheers!
Jul 19 '05 #11

P: n/a
Michael wrote:
On Sat, 20 Mar 2004 22:10:09 +0000, Gunnar Hjalmarsson wrote:
did you try my advice to load the CGI::Carp module and import the
'fatalsToBrowser' routine?
I tried it. With "require '$require_file';" I receive the
following error message:

http://bfr.caseywest.com/archives/001059.html


That is not an error message.
With "require $require_file;" the script terminates without any
output.

I have checked to make sure that the directory where the files are,
are in @ic. I added the directory with "use lib". I then have a
"print @INC;" statement that outputs all of the directories in @INC
and it does print the one where the files I need are. However,
when I use the second version of the $require statement (the one
without single quotes) there is no output from the script.


I have a feeling that you may be messing up the paths. If the $path
variable contains the *full* path to the directory, there should not
be a need to add any "use lib" statement. You'd better ensure that
$path is the full path. (As long as the $path variable contains
anything, but something else but the full path, a "use lib" statement
won't help.)

Also, did you see Joe's advice?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #12

P: n/a
On Sat, 20 Mar 2004 23:49:57 +0000, Gunnar Hjalmarsson wrote:

http://bfr.caseywest.com/archives/001059.html
That is not an error message.


Oops. It should have been:

Can't locate $require_file in @INC
With "require $require_file;" the script terminates without any
output.

I have checked to make sure that the directory where the files are,
are in @ic. I added the directory with "use lib". I then have a
"print @INC;" statement that outputs all of the directories in @INC
and it does print the one where the files I need are. However,
when I use the second version of the $require statement (the one
without single quotes) there is no output from the script.


I have a feeling that you may be messing up the paths. If the $path
variable contains the *full* path to the directory, there should not
be a need to add any "use lib" statement. You'd better ensure that
$path is the full path. (As long as the $path variable contains
anything, but something else but the full path, a "use lib" statement
won't help.)


I believe that $path contains the full path to the files. I printed the
path out in the loop just before each "require" statement and it is the
path to the files as far as I know them to be, unless the server is using
some kind of aliasing or symbolic links that I am unaware of.
Also, did you see Joe's advice?


I did see Joe's advice. Each file has the "1;" at the end.
Cheers!

Jul 19 '05 #13

P: n/a
Another idea is to replace

require $require_file;

with

eval { require $require_file };
die $@ if $@;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #14

P: n/a
On Sun, 21 Mar 2004 00:41:26 +0000, Gunnar Hjalmarsson wrote:
Another idea is to replace

require $require_file;

with

eval { require $require_file };
die $@ if $@;


I get the same result with both. Script terminates with no output.

rats.
I appreciate your help, but I feel that I must have taken up more of your
time than this little problem of mine deserves.

I believe I have two options:

1) continue to struggle to get this script to work.

2) rewrite it from scratch. Of course in this option I would likely
rewrite it in a scripting language that I have more experience with (PHP
or Python)
I really do appreciate your efforts and your patience with my lack of Perl
knowledge.
Cheers!
Jul 19 '05 #15

P: n/a
On Thu, 18 Mar 2004 06:50:47 -0500, Michael wrote:

Guten Morgen Once Again,
Well, instead of fighting with the script all weekend long, or porting it
over to another language, I queried the client to make certain that this
was indeed the correct code to install on the server. The client sent the
code again. This time it runs.

It turns out the code was edited and zipped in Windows. When I unzipped
it in Linux the files turned out a bit differently (I understand the
unzipping in Linux does not strip out some DOS/Windows carriage returns).
I went back and unzipped the original code given by the client in Windows
and then re-installed it and again it worked.
My face is as red as my socks.

rats.
Cheers!
Jul 19 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.