in reply to Re^2: symbolic references in a hash lookup
in thread symbolic references in a hash lookup
That didn't exist in your code, so I didn't use that.
Symbolic refs only access package variables. You never assigned a value to the $setter package variable, the error message is correct.
There's no reason to replace the simple if/else with a lookup table (which is what you are trying to do, really). In fact, why are you creating two subs when you only even want one? Simpler:
for my $name (keys %{$accessors}){ my $accessor; if( $accessors->{$name} eq "setter" ){ $accessor = sub { ... }; } else { $accessor = sub { ... }; } no strict 'refs'; *$name = $accessor; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: symbolic references in a hash lookup
by bot403 (Beadle) on Jun 12, 2009 at 18:35 UTC |