in reply to Static Variables in Perl
package Parent; our $knob = 1; sub knob { my $class = shift; $knob = $_[0] if @_; return $knob; } package Child; use base 'Parent'; # inherits knob method
That way, calling Parent->knob or Child->knob will get and set the same package global in Parent. To make it safer, you could make $knob a lexical, so it's only visible via the method call.
Update: Better mutator code per Tanktalus's comment.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Static Variables in Perl
by Tanktalus (Canon) on Mar 30, 2006 at 20:32 UTC |