On Mon, Apr 20, 2009 at 11:21, Dermot <[email protected]> wrote:
> Hi,
>
> I am trying to initiate a hash once when the package is loaded (via
> modperl). I don't want to make repeated DB queries for this data so
> I'd like to populate the hash when my daemon starts and not again
> until it's reloaded/started. I thought that I could say somethign
> like, "if %defaults, return %defaults else populate %defaults and
> return".
>
> Here's the error I am getting:
>
> Can't modify private hash in logical or assignment (||=) at
> /export/web/lib/Foo.pm line 28, near "}
snip
You should have gone with your first instinct:
sub getDefaults {
return if %defaults;
my $sql = q{SELECT * from bar};
my $sth = $dbh->prepare($sql);
$sth->execute;
while (my $row = fetchrow_hashref) {
$defaults{$row->{id}} = $row->{'description'};
}
return
}
You might also want to look into the Singleton pattern[1].
1. http://en.wikipedia.org/wiki/Singleton_pattern
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/