I am doing some Object Oriented programming in Perl.
I have a problem getting the instance variables in some of my
classes updated.
If I update one variable in a class that contains several instance variables,
then the other variable does not keep its original value, it gets the
same value as the variable I have updated.
Example code:
#my class constructor
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $self = [];
$self ->[ACCESS_METHOD] = undef;
$self ->[TOTAL_ACCESS_TIME] = undef;
$self ->[HOURLY_ACCESSES] = [23];
return bless $self, $class;
}
#how to set an accessmethod
sub accessmethod{
my $self = shift;
if (@_) { $self->[ACCESS_METHOD] = shift }
return $self->[ACCESS_METHOD];
}#end accessmethod
#here the problem occurs when trying to update an instance variable.
sub add_time{
my $self = shift;
my ($seconds) = @_;
#the problem is that now access method is also set to seconds!!!!!
$self->[$TOTAL_ACCESS_TIME] += $seconds;
}
I would be greatfull for any help.
Regards
Sara
--
Get your firstname@lastname email for FREE at http://Nameplanet.com/?su
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]