Home: Perl Programming Help: Beginner:
Undefined subroutine error



PerlyTrey
New User

Oct 3, 2012, 11:48 AM


Views: 2706
Undefined subroutine error

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


Views: 2704
Re: [PerlyTrey] Undefined subroutine error

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


Views: 2695
Re: [PerlyTrey] Undefined subroutine error

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