in reply to OOP Access of variables
Then TArt::Editor invokes the method:package TArtLib; use strict; use vars qw($dbh); ... sub dbh { return $dbh; }
Note the usage of TArtLib inside of TArt::Editor; that relieves the code which calls TArt::Editor from knowing what other modules are required.package TArt::Editor; use TArtLib; ... my $dbh = TArtLib->dbh;
The dbh class method would also be a good place to initialize things (or call an initialization method) if $dbh is false.
Update:If what you want is one-time initialization, then this is definitely the way to go. Don't use the package $dbh directly, but go through a method as shown here; and use that method to do the one-time initialization:
sub dbh { unless ($dbh) { # connect to the database now. } return $dbh; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: OOP Access of variables
by simeon2000 (Monk) on Mar 08, 2001 at 21:35 UTC | |
by TheoPetersen (Priest) on Mar 08, 2001 at 21:38 UTC | |
by simeon2000 (Monk) on Mar 08, 2001 at 22:02 UTC | |
by Masem (Monsignor) on Mar 08, 2001 at 22:46 UTC |