nysus has asked for the wisdom of the Perl Monks concerning the following question:
...I'm wondering why the "_accessible" subroutine needs to be called with $self-> in front of it. In other words, why does plain oldsub AUTOLOAD { my ($self) = @_; $AUTOLOAD =~ /.*::get(_\w+)/ or croak "No such method: $AUTOLOAD"; $self->_accessible($1) or croak "No such attribute: $1"; $self->{_read_count}++; return $self->{$1} }
Doesn't the %attrs hash stay alive after leaving the scope because it is referenced in the _accessible subroutine? And what exactly does putting the $self-> in front of the subroutine do differently to prevent the error? Thanks.{ my %_attrs = ( _name => undef, _artist => undef, ); sub _accessible { exists $_attrs{$_[1]}} }
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop";
$nysus = $PM . $MCF;
Click here if you love Perl Monks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Need help understanding variable scope in modules
by tye (Sage) on Jul 11, 2001 at 22:41 UTC | |
by Abigail (Deacon) on Jul 11, 2001 at 23:23 UTC | |
by runrig (Abbot) on Jul 11, 2001 at 23:35 UTC | |
by tye (Sage) on Jul 11, 2001 at 23:48 UTC | |
by BrentDax (Hermit) on Jul 12, 2001 at 00:16 UTC | |
|
Re: Need help understanding variable scope in modules
by japhy (Canon) on Jul 11, 2001 at 22:31 UTC | |
by nysus (Parson) on Jul 11, 2001 at 22:40 UTC | |
by japhy (Canon) on Jul 11, 2001 at 22:53 UTC |