Hi all,

I have just started learning perl and OOPs concepts. I have a query regarding perl OOP concept.

Below is a standard piece of code showing class implementation. I understand with limited knowledge that $self is a reference to a hash, and this hash gets converted to an object after getting blessed. Blessing essentially means that the $self hash can now use any function in XYZ class for manipulation. Please correct me if I am wrong anywhere.

I have mostly come across examples where constructor function, such as "new" here contains a hash that gets blessed within the constructor. Many a times this hash may be nested to form a complex data structure. However, suppose instead of having one complex hash structures I choose to have two simple hash structures (say $self1 and $self2) . My question is, can we have two hashes (say $self1 and $self2) and both being blessed with the same class within the constructor. Is this allowed? If yes, then do $self1 and $self2 form two separate objects after being blessed. How then are $self1 and $self2 connected/related in anayway? Also, what are advantages of having a complex single hash vis a vis two simple hashes? I am actually confused. I guess I am missing something here.

Please advise.

Thanks,

package XYZ; sub new { my $class = shift; my $self = {}; return bless $self, $class; }

In reply to Perl OOP by newbio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.