in reply to Accessing class/subclass variables

A big question is what you're using this for. There are a few basic scenarios:

My money is on the constant. That's 90% of all class variable usage.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Accessing class/subclass variables
by nmerriweather (Friar) on Mar 25, 2006 at 08:46 UTC
    It's two class variables - one is a hash, the other is an array of hashes, so sticking them in a constant is messy ( because then its a constant to an anonymous ref , which is a PITA when dereferencing. Both are used by class instances as configuration settings- i glanced at teh code the other day and realized 'hey, with a few more lines i could totally abract these 3 functions into 1' and did.

    For now, I just stuck a reference to the data in the instance, but i hate doing that with these structures, because now instead of:
    sub func(){ my ($self) = @_; foreach my $a (@b){} foreach my $a (keys %c){} }
    i have
    sub func(){ my ($self) = @_; my @b = @{$self->{'_class_b'}} my %c = %{$self->{'_class_c'}} ... }
    which does that annoying coercion into a new array / hash ( i can't just deref and address the needed items, as i need t o loop and nest through them all)