We don't bite newbies here... much | |
PerlMonks |
Re: Perl OOPby gmpassos (Priest) |
on Oct 11, 2004 at 22:15 UTC ( [id://398315]=note: print w/replies, xml ) | Need Help?? |
What can make you to understand better is to know the meaning of the code {}.
{} means a reference to an anonoymous HASH. Is the same thing of the code above, but without give a name to the hash: Other thing that you should know is that each time that you make \%foo or {} we will point to a new HASH. So, each time that we go inside the sub new(), a new %foo will be created (since %foo is local due my). Or each time that we execute {} we have a reference to a new anonymous HASH. We can see that above: Output: Note that the array @hold_ref is just to ensure that we won't have new HASHES created in the same address of old hashes already cleanned from the memory. So, bless() will always bless a new reference, what means that we have a new object (well this is why we call by the name new() or create()). The meaning of bless is to say that some reference belong to a package/class, and with that we can do a lot of things, and one of them is to call a method, that is the basic of Object Orientation. Other question is "Why Perl does OO with a reference to some data structure that belongs to a package?". Well, the main purpose of OO is to have a data structure related to the methods that will interact/change this data. Well, actually OO borned in this way, but they forgot to tell this to us.
Graciliano M. P.
In Section
Seekers of Perl Wisdom
|
|