R
robert.waters
Hello,
I need to keep track of a list of items in my package/object;
currently, I am going about it like this:
sub new {
my $self = { _listofstuff => undef };
bless $self;
return $self;
}
sub dostuff {
my $self =shift;
for (my $i=0; $i<10 ;$i++) {
push @{$self->{_listofstuff}), "listitem";
}
}
Is there a better way? Using '$self->underscored-hash-item' is
tedious, but I am willing to deal with it; however, having to treat
this hash element as an array in order to use it as such (rather than
declaring it as an array to begin with) seems hackish. I would very
much love to just see '@listofstuff'.
Can't I just declare an array in the top-level scope and pass it around
as a reference from function to function? Or would this create a class
variable, shared by each instance?
Thank you very much,
Robert
(a perl OOP beginner)
I need to keep track of a list of items in my package/object;
currently, I am going about it like this:
sub new {
my $self = { _listofstuff => undef };
bless $self;
return $self;
}
sub dostuff {
my $self =shift;
for (my $i=0; $i<10 ;$i++) {
push @{$self->{_listofstuff}), "listitem";
}
}
Is there a better way? Using '$self->underscored-hash-item' is
tedious, but I am willing to deal with it; however, having to treat
this hash element as an array in order to use it as such (rather than
declaring it as an array to begin with) seems hackish. I would very
much love to just see '@listofstuff'.
Can't I just declare an array in the top-level scope and pass it around
as a reference from function to function? Or would this create a class
variable, shared by each instance?
Thank you very much,
Robert
(a perl OOP beginner)