Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Module Confusion?

by Ronnie (Scribe)
on Dec 07, 2006 at 11:25 UTC ( #588294=perlquestion: print w/replies, xml ) Need Help??

Ronnie has asked for the wisdom of the Perl Monks concerning the following question:

Hello ther inmates can you point a very confused monk in the right direction please?! I've written a new Perl script that loads 2 of my own in-house written modules -
############################################################### use lib '/home/interface/scripts/Perl_Modules' ; # Where the in-ho +use modules live # # In-House written modules #--------------------------# use ACC_Heather ; use ACC_Various qw(end_it mail mail_log update_report date_validation) + ;
The problem is that the ACC_Heather module uses some of the subroutines contained within ACC_Various. I thought that this would be simple enough - it may well be but I'm probably a lot simpler!! I put a use ACC_Various inside the ACC_Heather module :-
package ACC_Heather ; # our @EXPORT = qw(ACC_IHS_PROFILE run_SQLPLUS ACC_PUT_STEP ACC_GET_STEP + ACC_BOX Update_Job_Status_Log ) ; #our @EXPORT_OK = qw() ; use Exporter ; our @ISA = qw(Exporter) ; # use ACC_Various qw(end_it mail mail_log update_report date_validation) + ;
thinking that if I prefixed every call of an ACC_Various subroutine within ACC_Heather with ACC_Various:: everything would be fine.
if (! -e $SQL_script) { $msg = "SQL script $SQL_script does not exist" ; if (! ACC_Various::&update_report("$logfile","$msg",1,1,0)) { print "\n\tUnable to run Sub update_report :: $!\n" ; } print "\n\t$msg\n" ; print "\t*****************************************\n" ; print "\t* Contact Analyst in Team 1 - Urgently! *\n" ; print "\t*****************************************\n" ; return 0 ; }
Nope!! I got that wrong! The very first call to update report results in the following error :-
Undefined subroutine &ACC_Heather::update_report called at /home/inter +face/scrip ts/Perl_Modules/ line 737.
Am I missing something very obvious or can/should this not be done? See what I mean about confusion! (Okay I admit it I made a typo in a reply!) I've tried all of the following :-


All resulting in the same error. I use ACC_Various in lots of other scripts but this is the first time I've tried using it within another module. The EXPORT etc of ACC_Various is :-
package ACC_Various ; # our @EXPORT = qw(end_it mail mail_log date_validation ACC_BOX) ; our @EXPORT_OK = qw(run_SQLPLUS update_report error_report) ; use Exporter ; our @ISA = qw(Exporter) ; #
Any other suggestions? I could be really boring and copy all of the subroutines from ACC_Various into ACC_Heather but .... I'd learn nothing. Thanks in advance.

************************************************************ Sorry guys you're dealing with an idiot!!!! Officially! * * When I made the changes to my code I wasn't in the * * directory I thought I was and as a result I was using * * the original failing code all the time!!! * * * * I'd shoot myself but I'd probably MISS!!!!! * ***********************************************************

Replies are listed 'Best First'.
Re: Module Confusion?
by themage (Friar) on Dec 07, 2006 at 11:40 UTC
    Hi Ronnie,

    Once you already have the use ACC_Various qw(... update_report ...); line in your use, you don't need to prefix the update_report call with the ACC_Various.

    Anyway, you are calling it the wrong way (I presume it was a typo, as it would give you a syntax error as is - at least in perl 5.8). To call ACC_Various with the prefix you can do it using two diferent ways:
    ACC_Various::update_report(...); &ACC_Various::update_report(...);
    As you have the use importing the update_report, you can also call it with:
    Update: As the error message is about Undefined subroutine &ACC_Heather::update_report I would say that your use is not doing the expected, or that you are not adding update_report to our @EXPORT or our @EXPORT_OK in ACC_Various.

    Hope this clarifies your questions.

    Talking Web
Re: Module Confusion?
by jonadab (Parson) on Dec 07, 2006 at 11:34 UTC

    I have never seen things written quite this way before. Specifically, the ::& part rubs me the wrong way. It's the sort of thing I'd expect to see in the obfuscation section here, but not in normal code. Unless I am seriously mistaken about what you are trying to do, you don't need the ampersand there, and it may even be causing your problem.

    In the first place, a sigil on a package-scoped item normally goes at the beginning, as in $Some::Package::variable, and in the second place, the ampersand sigil on subroutines is usually not used when calling them, unless you have a specific reason to want its particular magic with regard to special variables. (The amp _is_ often used when taking a reference to a subroutine, but that is another matter.)

    Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.
      The & was desperation as i'd tried it with just :-

      getting the same result. Sorry for the extra confusion!
Re: Module Confusion?
by reneeb (Chaplain) on Dec 07, 2006 at 11:42 UTC
    ACC_Various::&update_report("$logfile","$msg",1,1,0) should be

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://588294]
Approved by aufflick
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-10-07 13:40 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (30 votes). Check out past polls.