Gossamer Forum
Home : General : Perl Programming :

custom sub not loading

Quote Reply
custom sub not loading
i have a file format.pl that contains sub html_admin_menu ...

i have a file members.pl that contains:
Code:
require format.pl

sub html_admin_menu ...

db.cgi is the executable script and requires members.pl

in the past i've included any customized versions of subs in format.pl in members.pl. this always overrode the sub in format. suddenly, this isn't working -- it keeps running the sub in format instead of members. i don't think i've changed anything... what could be causing this?
Quote Reply
Re: [delicia] custom sub not loading In reply to
i just tested some other custom subs in members.pl and they are working correctly.
Quote Reply
Re: [delicia] custom sub not loading In reply to
at the end of format.pl, do you have:

Code:
1;

(to tell it that the module is finished)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] custom sub not loading In reply to
yes. both format.pl and members.pl have 1; at the end. i think all my .pl files do.
Quote Reply
Re: [delicia] custom sub not loading In reply to
You have:

Code:
require format.pl;

sub html_admin_menu ...

or:

Code:
require format.pl

sub html_admin_menu ...

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] custom sub not loading In reply to
require format.pl;

i just left off punctuation while typing the post. lazy!
Quote Reply
Re: [delicia] custom sub not loading In reply to
So just to be clear, what is the exact problem? You have 2 functions named the same? One in the original script, and then again in the "required" script?

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] custom sub not loading In reply to
i think you've got it. or maybe you have it backwards.

1. db.cgi calls members.pl
2. at the beginning of members, format is required
3. format has sub html_admin_menu
4. members.pl also has a sub html_admin_menu AFTER the require format.pl statement

there are other duplicate subs where i have customized. this is the only one that isn't working.

Last edited by:

delicia: Jan 21, 2021, 9:07 AM
Quote Reply
Re: [delicia] custom sub not loading In reply to
You should never use the same function names if you are going to be using the same namespace. Try renaming one of them, and see if that helps

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] custom sub not loading In reply to
i thought you could have two subs with same name and perl would use whichever was last. i don't know what namespace means. Frown
like i said, the others work.

ooh, i think i figured it out! the other subs that work are required in db.cgi instead of members.pl. i'll try moving some things around. thanks!
Quote Reply
Re: [delicia] custom sub not loading In reply to
that did it!!!! thanks!!!!!
Quote Reply
Re: [delicia] custom sub not loading In reply to
Hi,

Its never good having subs with the same name. If you were using a module, its not so far - for example;

Test.pm:
Code:
package Test;

sub foo {
print "YES!";
}

1;

Test2.pm:
Code:
package Test2;

sub foo {
print "BLA!";
}

1;

test.cgi:

Code:
use Test;
use Test2;

print Test::foo();

Thats fine, as you are explicitly specifying how you call it (i.e which module). Also, I expect if you had the -w flag set on the "shebang" (path to perl) you would get an error about the function name being re-defined :)

Anyway - glad you sorted it Angelic

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!