in reply to Iterating over an array of objects, within an object?
To say it a bit shorter than GrandFather, $self->{objs} is a reference to your array. A reference is a scalar, so all you're iterating over is that one reference.
What you want instead of course is to iterate over the elements of your array. So to get from your array reference to your array, you need to dereference it. So you need @{$self->{objs}}, which turns your code into:
package Foo; ... sub doStuff { my $self = shift; foreach my $obj (@{$self->{objs}}) { $obj->doSomethingElse(); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Iterating over an array of objects, within an object?
by GrandFather (Saint) on Dec 19, 2006 at 02:07 UTC |