ninja-joe has asked for the wisdom of the Perl Monks concerning the following question:
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 likesub 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; }
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.sub data { my $self = shift; my $bar = shift; if(@_) { $data{$bar} = $self->{FOO}; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tying with a class method
by broquaint (Abbot) on May 02, 2002 at 15:24 UTC | |
by ninja-joe (Monk) on May 02, 2002 at 16:49 UTC | |
by broquaint (Abbot) on May 02, 2002 at 17:09 UTC |