CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Undefined subroutine... ?


mike robb

Sep 14, 2000, 6:13 PM

Post #1 of 3 (1110 views)
Undefined subroutine... ? Can't Post

I have been porting working perl scripts from one server to another - both running apache on linux. I ziped up the files ported over and unziped (-a option!) on the new server.

I am now getting a server log error (in the apache error log file)

Undefined subroutine &SmallPig::get_config called at /home/q8/public_html/cgi-bi
n/forum/sporum/cindex.cgi line 12.
[Thu Sep 14 22:05:04 2000] [error] [client] Premature end of scr
ipt headers: /home/q8/public_html/cgi-bin/forum/sporum/cindex.cgi

The subroutine SmallPig::get_config exists in the parent directory and I have the code (verified working correctly) that has inserted the correct path (INC):

Undefined subroutine &SmallPig::get_config called at /home/q8/public_html/cgi-bi
n/forum/sporum/cindex.cgi line 12.
[Thu Sep 14 22:05:04 2000] [error] [client] Premature end of scr
ipt headers: /home/q8/public_html/cgi-bin/forum/sporum/cindex.cgi

The above error poped out if I put a "use SmallPig" prior to the call to the subroutine.

it seems obvoius to me that there is another problem that is causing me to need the "use" statement on my new server.

Any idea what would change to cause me to need to use the "use" statement?

[if i need to post more information please let me know and i will Smile]


User / Moderator

Sep 15, 2000, 4:21 AM

Post #2 of 3 (1111 views)
Re: Undefined subroutine... ? [In reply to] Can't Post


Here is what it looks like to me. Forgive me if I don't get it right.

First off, you have the module SmallPig. You
are calling the subroutine get_config and get the error that is undefined unless you say 'use SmallPig'.

Well, SmallPig is a module and you must, in your script either 'use' or 'require' it.
Since it is not in the standard Perl Module Library (I don't think I've seen it on CPAN but then again there are hundreds of modules on CPAN), I would think there should be included some reference to 'use' or 'require'
it or it's directory should be in the 'lib' path.

If you were using the Perl Builder IDE and had it open as a module when you tested the script that calls it, Perl Builder will not give you that error. It will however happen on a real server.

Things to try:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

use lib qw( /SmallPig/Directory );
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

use SmallPig;
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

require SmallPig;

Also, could it be the SmallPig sit's in the cgi-bin directory and you are calling it from a script to subdirectories deep?

I one of these is the reason, but would need
more detail to determine exact cause.



mike robb

Sep 15, 2000, 1:22 PM

Post #3 of 3 (1110 views)
Re: Undefined subroutine... ? [In reply to] Can't Post

the module is part of a forum system (open source project) - if you are interested in exactly what the bigger picture is all about.

this module is one of many many modules that comprise the forum.

I have a working setup of this forum on one server and ziped up the entire file structure and ported the zip file to the new server. on this new server i unzipped the files (-a option to preserve the ascii representation of the perl files!)

so all the files are exactly the same as they are on the working system.

the next step was to make modifications to the configuration files that specify paths to files and the like.

after this step i was trying to run the system and the file in question is run via the web browser (or telnet as it does not matter to get the error) and it can not find the module

On the current working server forum system the file (exactly as it is with no "use" or "require" that i'm aware of) works fine, but the new server file does not.

I have included the file below for completeness.

the INC path does get updated correct - as i have put print statements in to see what is going on)


my ($fbconfig, $config);
use FVars;
$fbconfig = FVars::get_fconfig();
unshift(@INC, $fbconfig->{sp_cgi});

$config = SmallPig::get_config();

use FDB;
use FCGI;

use strict;

sub main{
# print "Content-type: text/html\n\n";

my $spdb = FDB->new($config);

my $spcgi = FCGI->new($spdb, "cindex", $config);

my $STATE = $spcgi->{'STATE'};
my $op = $STATE->{'op'};

# --- create a templa1te object
my $template;
require Templates::CIndex;

$template = Templates::CIndex->new($spcgi, $spdb);

# --- print the http header

---end of file---


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives