Charles K. Clarkson <[EMAIL PROTECTED]> wrote:
> [snip]
> : : foreach my $method ( keys %InheritableClassData ) {
> : : no strict 'refs';
> : : *$method = sub {
> : : shift;
> : : $InheritableClassData{$_} = shift if @_;
> : : return $InheritableClassData{$_};
> : : };
> : : }
> [snip]
Perhaps it's just me, but I find the following approach to be clearer
for generating accessors:
==CODE==
#!/usr/bin/perl
use strict;
use warnings;
package test;
our %InheritableClassData;
for my $aa (qw/aa bb cc/) {
eval qq(
sub $aa {
shift;
\$InheritableClassData{$aa} = shift if [EMAIL PROTECTED];
return \$InheritableClassData{$aa};
}
);
}
package main;
print "$_\n" for %{*test::};
=/CODE==
Michael Kraus <[EMAIL PROTECTED]> wrote:
> : Should I be using "my" or "our" here for the variables - these
> : are the variables I want present in all my derived classes and
> : should be the same for all.
I assume you're referring to things like %InheritableClassData... You
should be using "our" variables; "my" variables won't be visible from
outside the class in which they're declared.
Cheers,
Dave
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>