Solution: use constant NAME => 'vB'; Then, you say $class->NAME or $obj->NAME and you'll get the right one.
Solution: You need a place for class data and a method of accessing it. The simplest way would be something like:
The only drawback is that you have to cut'n'paste this code in every class. Furthermore, you have to pre-seed the items in the %data hash. But, it may be sufficient and it is really simple.{ my %data = ( name => 'vB', ); sub access_class_data { my $class = shift; my ($name, $val) = @_; return $class->SUPER::access_class_data( @_ ) unless exists $data{ $name }; if ( @_ > 1 ) { $data{ $name } = $val; } return $data{ $name }; } }
Solution: Put it in the instance.
My money is on the constant. That's 90% of all class variable usage.
In reply to Re: Accessing class/subclass variables
by dragonchild
in thread Accessing class/subclass variables
by nmerriweather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |