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 "}
Below is what I've attempted so far. Can someone give me a few pointers please?
Thanx,
Dp.
package: Foo;
use strict;
use warnings;
use DBI;
my %defaults;
sub getDefaults {
%defaults ||= do {
my $sql = q{SELECT * from bar};
my $sth = $dbh->prepare($sql);
$sth->execute;
my %vals;
while (my $row = fetchrow_hashref) {
%vals{$row->{id}} = $row->{'description'};
}
%vals;
} # Does this need a semi-colon?
# Should I reurn here or return
%defauls ||= do {...}
}
1; #end of package.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/