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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Undefined subroutine error

 



PerlyTrey
New User

Oct 3, 2012, 11:48 AM

Post #1 of 3 (1230 views)
Undefined subroutine error Can't Post

I have written a perl script that is supposed to call a subroutine (PrintPageHeader) in another script (PageHeader.pl). (The PrintPageHeader subroutine prints the html code for the header portion of a webpage that is used in several scripts). My calling perl script uses require '/fullpathtoscript/PageHeader.pl'. Later the script calls the subroutine with its parameters PrintPageHeader($ClientName, $ClientLogo);

The problem that I am having is that sometimes I am getting the error message "Undefined subroutine &ModPerl::ROOT::ModPerl::Registry::website_thrasherandheckman_2dsecure_cgi_2dbin_Caseshow_2epl::PrintPageHeader called at /website/thrasherandheckman-secure/cgi-bin/Caseshow.pl line 45. " I cannot understand how this error is happening. It is happening intermittently but regularly. Sometimes, the error will occur when the page initially displays properly and I hit refresh.

Any ideas what might cause this problem?


wickedxter
User

Oct 3, 2012, 12:57 PM

Post #2 of 3 (1228 views)
Re: [PerlyTrey] Undefined subroutine error [In reply to] Can't Post

use the module lib and this will add a directory to the @INC where perl stores directories to look threw for modules or scripts. it will need to be in all scripts the require PrintHeader.pl file.

The error is comming from it not finding the PageHeader.pl and useing lib module should fix that.


Code
use lib qw(/usr/bin/dir/to/base/ c:/dir/to/base/); 
use strict;
use warnings;


#require the script
require PageHeader.pl;

Code



      
    


FishMonger
Veteran / Moderator

Oct 3, 2012, 4:59 PM

Post #3 of 3 (1219 views)
Re: [PerlyTrey] Undefined subroutine error [In reply to] Can't Post

Another improvement would be to convert the script into a true module which exports its subs.

 
 


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

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