Suppose I have a class, and I want to have a persistent tie to a dbm file. I'm using strict also.
I want to have two subs, a connect and disconnect. If I were to do
sub connect {
my $self = shift;
tie %data, "AnyDBM_File", "data", O_RDWR, 0644
or die "Cannot open data for read.\n";
return 1;
}
sub disconnect {
untie %data;
}
Would it work the way I'd hope it would? Or would the tie to data be lost because of the scope of the sub?
Could I then do something like
sub data {
my $self = shift;
my $bar = shift;
if(@_) {
$data{$bar} = $self->{FOO};
}
}
And expect it to behave correctly?
Perhaps it would be better to tie the dbm file to a class member, but I don't know how one would do that.