Home  |  Linux  | Mysql  | PHP  | XML
From:Paweł Prędki Date:Sun Nov 29 01:04:54 2009
Subject:problems with 'require'
Hey,
I've been using simple CGI scripts to make some things on my website
require less human touch and some of them require mysql database
connection. I've started with only one such scripts but now there are
more so I've decided to move the connection data (table name, database
name, username, password) to a separate .pm file which I could include
in the other .cgi scripts. However, I don't seem to be able to use the
functions and/or variables in this .pm module and I have no idea what is
wrong. Let me give you a simple example of what works and what doesn't
and I would really appreciate any help.

<file mydbtest.pm>
package dbredwings;

my $platform = "mysql";
my $database = "dbplayers";
my $host = "localhost";
my $tablename = "players";
my $user = "player";
my $pw = "pass";

sub printout {
print shift;
}

sub get_platform {
print $platform;
}
1;
</file mydbtest.pm>

<file properscript.cgi>
require 'mydbtest.pm';
print "Content-type: text/html\n\n";
&mydbtest::printout('hey hey'); # (1)
&mydbtest::get_platform; # (2)
print $mydbtest::platform; # (3)
</file properscript.cgi>

(1) works without any problems. I get the proper output in my browser
window.
(2) doesn't work at all. I get an error as follows:
Undefined subroutine &mydbtest::get_platform called at
E:/webdev/perl/properscript.cgi line 42.
(3) prints an empty string

Also, I get an error message saying that the .pm file can't be found
when I place it in the same directory as the .cgi files. I have to move
it to a directory in the @INC array when I run it through the server.
However, when I run it locally, from the command line, everything works
just fine. This makes me think that there is something in the Apache
config that I have to do in order for all this to work but I don't know
what that is.

I'm running ActivePerl 5.10.1 with Apache2.2 with mod_perl.
Alias /perl "E:\webdev\perl"
<Location /perl>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
Options +ExecCGI
PerlOptions +ParseHeaders
</Location>
ScriptAlias /cgi-bin/ "E:/webdev/perl/cgi-bin/"

Cheers,
palo
Navigate in group perl.beginners.cgi at sever nntp.perl.org
Previous Next


Your recent visits
Re: problems with 'require'
cgi and perl database interaction
Saving data to %session with Apache::Session::File
Re: 2 off in array count and index
Re: Need help to resove..... ExtUtils-Makemaker comilationS



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants