badoosan has asked for the wisdom of the Perl Monks concerning the following question:
I've been clumping along with procedural Perl for some time now and decided it's time to move into oop. So, I know how to create the package and how to reference the objects from my main program. What I can't seem to figure out is how do I call another subroutine (remember I'm coming from the land of procedural Perl) from within my package object. In very simple terms what I'm doing is:
1. There's a file called something.cgi. This has the appropriate require statements and calls a subroutine called getHeader($parm).
2. The getHeader subroutine lives in getheader.pl It is NOT a package.
3. There is a subroutine call dbSelect() that lives in dbselect.pl. This is NOT a package.
4. The getHeader subroutine creates an instance of the object Staff. Staff is in staff.pm. All is happy up to this point.
5. The getHeader subroutine calls the getFullName method in the Staff package. Here's the problem. getFullName has a call to dbSelect (the procedural subroutine that is stored in another file - dbselect.pl). At this point I get an error message telling me that the subroutine &Staff::dbSelect is not found!
I've tried every combination of use and require that seems logical and still no joy.
I would be most appreciative if someone could point out what I'm doing wrong. I think this should be simple but I'm just not getting it.
Thank you in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling external subroutine from a package
by Anonymous Monk on Oct 15, 2012 at 17:31 UTC | |
by badoosan (Initiate) on Oct 15, 2012 at 17:47 UTC | |
by Anonymous Monk on Oct 15, 2012 at 17:33 UTC |