Angel has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
I have read many things on perl objects and have made a few. But I am perplexed at how to do hashes inside the object.
To give example I want the self hash to have a hash inside it to store things. I would greatly appreciate an example constructor, and get and set methods by key and possibly how to get the hash for internal methods
sub new { my $self = {}; #error reporting and update vars $self->{'error_type'} = undef; $self->{'error_string'} = undef; $self->{'text'} = undef; $self->{'query'} = undef; $self->{'reference'} = undef; $self->{'dbh'} = undef; $self->{'tokens'} = %( how do i do this ) bless ($self); return $self; } sub set_token { my $self = shift; $self->{'token'}{'$_[0]'} = $_[1]; } sub get_token { my $self = shift; return $self->{'token'}{'$_[0]'}; } sub get_token_keys { my $self = shift; keys $self->{'token'}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hashes in Objects
by kilinrax (Deacon) on May 07, 2003 at 15:46 UTC | |
|
Re: Hashes in Objects
by halley (Prior) on May 07, 2003 at 15:58 UTC | |
|
Re: Hashes in Objects
by artist (Parson) on May 07, 2003 at 15:50 UTC | |
|
Re: Hashes in Objects
by hardburn (Abbot) on May 07, 2003 at 15:46 UTC |