As salva shows the bless is probably not where the time is. The cost is probably in the method calls. However the a benefit of an object is in added value in methods rather than just wrapping a hash up in a layer of setters and getters. Perl lets you mix and match styles to a very large extent so there need be no particular disincentive to exposing some of the tender underbelly of your objects by allowing direct access to the object's data as a pragmatic solution to a problem.

You can use speedy access to a hash and added value methods to get both the benefits of a hash and the benefits of an object. In fact, after a modest debate with a colleague recently I did exactly that for a class passed out of an API function. The 'public' fields of the object are well documented and are freely accessible by calling code. It helps that there is no interaction between fields and any 'sensitive' data is tucked away in undocumented (therefore notionally 'private') fields. The objects are used to provide access to a database back end and the methods on the object are mostly private functions concerned with translating the data between the public form for calling code and the form required by the database. Thus cheap and easy access to data fields and nice encapsulation of the database facing code.

True laziness is hard work

In reply to Re: Time efficiency of object creation in Perl (or the "bless" function) by GrandFather
in thread Time efficiency of object creation in Perl (or the "bless" function) by kikumbob

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.