ZX81Meister has asked for the wisdom of the Perl Monks concerning the following question:
Hi there, I've just discovered the means of OOP in Perl and got a newbie question... I've defined a class with attributes like this:
sub new { my $class = shift; my $s = {}; bless $s, $class; $s->{Laboratory} = new MotionSensorB('Laboratory', 'senMotion_H2_S1 +'); $s->{Fruitcellar} = new MotionSensorA('Fruitcellar', 'senMotion_H1_S1 +'); return $s; }
In the same package I want to loop through the attributes, that is, access the elements Laboratory and Fruitcellar:
sub event { my $c = shift; foreach my ??? (???) { print ??? . "\n"; }
I'm not so firm with arrays, hashes, references etc. and trying all sorts of combinations, but can't get it right. How can I achieve it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loop though class attributes
by Corion (Patriarch) on Feb 24, 2018 at 07:17 UTC | |
by ZX81Meister (Initiate) on Feb 24, 2018 at 07:46 UTC | |
by stevieb (Canon) on Feb 24, 2018 at 15:47 UTC | |
|
Re: Loop through class attributes
by choroba (Cardinal) on Feb 24, 2018 at 21:12 UTC |