in reply to Returing Multiple Items and possibly using an object

An alternate possibility would be to use the magic of the AUTOLOAD subroutine, to access data. This would allow for greater simplicity, when it comes to adding methods.
our $AUTOLOAD; sub AUTOLOAD { my $self = shift; ref($self) or return; # Non-OO/Not an autoloaded method..? return if ( $AUTOLOAD =~ /DESTROY/ ); # don't mess with garbage +collection ( my $method = $AUTOLOAD ) =~ s{.*::}{}; my ( $code, $name, $ATTRname ); if ( $method =~ /get_(\w+)/ ) { my $ATTRname = lc($1); # Could possibly do a check to make sure we have one of a group o +f specific # attributes with. # # if ( $ATTRname =~ /^(?:html_error_string|error_type|password_va +lid|user_id # |other|stuff|you|want|to|access)$/x # ) {} no strict qw{refs}; # create and register the method *{$AUTOLOAD} = sub { my $self = shift; return $self->{$ATTRname}; }; unshift @_, $self; goto &{$AUTOLOAD}; } return; }


Gyan Kapur
gyan.kapur@rhhllp.com

Replies are listed 'Best First'.
Re: Re: Returing Multiple Items and possibly using an object
by djantzen (Priest) on Nov 18, 2002 at 03:12 UTC