Hi,

this is probably a stupid question. The question is that I want a particular class of objects to have several attributes, one of them a list (array), the problem is that I can't get it to work, it only stores the last value, and when I try to join another array it doesn't work. If somebody could help me on this, I've tried some references and stuff but i couldn't figure it out:

package SpeechAct;

sub new {
        my $classname = shift;                  
        my $self = {};                                  
        bless($self, $classname);               
        $self->_init(@_);    
        return $self;   
}

sub _init {
my $self = shift;
$self->{OBJECT} = ("xpto1","xpto2"); ---> THE PROBLEM! It only stores xpto2
if (@_) {
my %extra = @_;
@$self{keys %extra} = values %extra;
}
}


And when i try to use this method:

sub object {
        my $self = shift;
        return $self->{OBJECT} unless @_;
        
        my @list = $self->{OBJECT};
        print "List: ", @list, " with ", scalar(@list) ," element\n";
        
        #push(@list, @_);
        print "new list: ", @list, "\n";
        
        #$self->{OBJECT} = @list;
        #print "New obj: ", $self->object ,"\n" ;
        return $self->{OBJECT};
}

When called like this

$sa->object("xpto3","xpto4");

i get :

newlist: xpto2xpto3xpto4                                ----> (lost the xpto1)
New obj; 3                                              ----> SIZE?!?


Thanks for any possible tip.. i'm lost... :(



-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to