Please advise on this.
package ABC; { sub new { my $hashref={}; my @array=(); my $arrayref=[]; $class=$_; bless ($hashref,$class); bless (@array,$class); bless ($arrayref,$class); return $hashref, @array, $arrayref; #I think I can only return one of these three data structures but not +all, right? } sub get { #To access $hashref, @array, and $arrayref } sub set { #To set $hashref, @array, and $arrayref } } 1; #main $object1=ABC->new(); #assuming ABC class returns $hashref $object2=ABC->new(); #assuming ABC class returns @array $object3=ABC->new(); #assuming ABC class returns $arrayref
Basically, I want to create a class ABC with three separate data structures, $hashref, @array, and $arrayref and I want some mechanism to manipulate the data in them. Questions are,
Q1. How do I make the constructor return all three data structures, $hashref, @array, and $arrayref when invoked. Is it possible? I understand that only one of these three can be returned by the constructor and not all together. Correct?
Q2. I guess with $object1,$object2,$object3, I am creating three different objects. Right? Is there a way by which I create just one object of ABC and through this object I am able to manipulate data in all three data structures of, $hashref, @array, and $arrayref.
Q3. Do I need to create three different sets of get() and set() functions each to manipulate $hashref, @array, and $arrayref respectively by creating their objects first, ie $object1,$object2,$object3 ?
Q4. I understand I can manipulate $hashref, @array, and $arrayref only through access functions like get() and set() and not directly like $object1->$hashref or something like it, am I correct?
Q5. Suppose I create a nested data structure reference in the constructor, say $all={}, that contains all three, $hashref, @array, and $arrayref and if I bless $all with class ABC, then I can create just one object which I can then use to manipulate the data contained in $hashref, @array, and $arrayref. Also, this way I may just need one set of get()/set(). Is this a feasible solution? Would a nested data structure of $hashref, @array, and $arrayref together be better solution than their three separate data structures? Perhaps, the nested structure might make the program slower, yes/no?
I am not sure if I am making sense. Am I missing something? Please let me have your comments guys. What are the common ways of doing such things? Please guide.
Thanks a lot!
Cheers, Raj
In reply to On Perl Objects! by newbio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |