oop array question

--0-337962595-1315048979=:86810
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

=0A=0AI'm trying to add a object to an array of objects.=A0 The code below =
is wrong.=0A=0A=0Asub add_widget=0A{=0A=A0=A0=A0 my $self =3D shift;=0A=A0=
=A0=A0 my $new_widget =3D shift;=0A=A0=A0=A0 push ( [at] ($self->{WIDGETS}), $n=
ew_widget );=0A}=0A=0ALater, I'm going to need to iterate over the array of=
widgets.=A0 How can I accomplish these 2 tasks?=0A=0A=0A=0A--=0ARonald Wei=
dner=0A
--0-337962595-1315048979=:86810--
Ron Weidner [ Sa, 03 September 2011 13:22 ] [ ID #2063938 ]

Re: oop array question

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 ( [at] ($self->{WIDGETS}), $new_widget );
> }

Hi Ron

You probably want

push [at] {$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 ( [at] {$self->{WIDGETS}}) {
:
}

HTH,

Rob

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Rob Dixon [ Sa, 03 September 2011 13:37 ] [ ID #2063940 ]
Perl » gmane.comp.lang.perl.beginners » oop array question

Vorheriges Thema: unit test case for this perl code
Nächstes Thema: how to do this in perl (from unix)