develooper Front page | perl.beginners | Postings from January 2002

Packages in CGI

Thread Next
From:
K Old
Date:
January 3, 2002 18:56
Subject:
Packages in CGI
Message ID:
200201032212.RAA01863@ns.oldcommunications.com
Hello all,

I have a few questions about using packages in CGI.  

First, here is my situation.  I am creating a account management and billing 
set of scripts and want to modularize it.  I have most (if not all of the 
code) scattered among several .pl files and not necessarily in subroutines, 
but can easily be put into subroutines.

Let's take one example.  I have a need to use a subroutine called 
do_billing() in more than one .pl file.

Now, I would assume that all I need to do to make this a package is at the 
top of the file with do_billing() in it, I just put

package MyPackageName;

Then in any file that I want to use it, I just make sure that the path to the 
folder that has MyPackageName.pm in it is in my @INC, and then put use 
MyPackageName; at the top of any given .pl file that wants to use it.

Now, from there, do I:

1) call the subroutine by 
                                    MyPackageName::do_billing();

2) call the subroutine by 
                                    $billing = new MyPackageName;
                                    $bill_results = $billing->do_billing();

Or, am I way off track?

Any help is appreciated.

Kevin

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About