On Wed, 6 Mar 2002, Joel Gwynn wrote:
> sub thisform {
> my $self = shift;
> my $dbh = $self->param('dbh');
> my $q = $self->query;
> ...
>
> I know it's not a huge pain to do this, but is there a better way to
> have each sub automatically know about $dbh, $q, etc. Is this a good
> idea? stupid question?
You can save a little typing without losing the good parts of lexical
variables using Perl 5.6's new our() variables:
sub setup {
# ...
# setup dbh and query package var
our $dbh = $self->param('dbh');
our $query = $self->query;
}
sub runmode {
our ($dbh, $query);
# ...
}
These are "safer" than real globals since they're lexically scoped but
they allow you to save some time by setting them up once for each request.
-sam
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]