oop array question
am 03.09.2011 13:22:59 von Ron Weidner
--0-337962595-1315048979=:86810
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
I'm trying to add a object to an array of objects.=A0 The code below =
is wrong.
=0Asub add_widget=0A{
my $self =3D shift;
=
my $new_widget =3D shift;
push ( @($self->{WIDGETS}), $n=
ew_widget );=0A}
Later, I'm going to need to iterate over the array of=
widgets.=A0 How can I accomplish these 2 tasks?
--=0ARonald Wei=
dner=0A
--0-337962595-1315048979=:86810--
Re: oop array question
am 03.09.2011 13:37:40 von Rob Dixon
On 03/09/2011 12:22, Ron Weidner wrote:
>
> I'm trying to add a object to an array of objects. The code below is
> wrong.
>
>
> sub add_widget
> {
> my $self = shift;
> my $new_widget = shift;
> push ( @($self->{WIDGETS}), $new_widget );
> }
Hi Ron
You probably want
push @{$self->{WIDGETS}}, $new_widget;
> Later, I'm going to need to iterate over the array of widgets. How
> can I accomplish these 2 tasks?
Simply
foreach (@{$self->{WIDGETS}}) {
:
}
HTH,
Rob
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/