Correct: new() is not a built-in. I assumed that it existed in the module, and that you just didn't include that portion of the code. Otherwise, the code you posted wouldn't have made much sense. new() is the "constructor" for the object, and it has to be written by the module's author. There's nothing special about the name new() either. DBI uses connect(), and other modules use other names that make sense as constructors for their respective classes. However, unless you have a good reason, new() is usually the most predictable and sensible name to use.

One thing: The code you posted is really a bad example to learn from. It's considered a bad practice to deal with the object's internals directly from outside the object, and that's what the example code is doing. The class's author should be free to implement the object however he wants internally, and expose its internals through well-defined accessors in a way that abstracts away the details of implementation. ...that's at least my opinion about what code I saw posted. But I understand you've got the hand of cards that some previous developer handed you. Just be aware that when it comes time to actually learn how to write OO in Perl, Intermediate Perl is an excellent resource. And Modern Perl (by chromatic) will get you started with Moose (Perl's newer, more palatable object system).


Dave


In reply to Re^3: I have a perl snippet. And I need help understanding it. Can you help answer these questions. by davido
in thread I have a perl snippet. And I need help understanding it. Can you help answer these questions. by Fighter2

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.