Are you asking how to make constructors? If you are, the docs that come with Perl are pretty good in this regard. If you're just confused about passing arguments on to a constructor, this oughta help you:

First, a method is the same as a subroutine. The only difference is it gets passed some extra info and is called a different way.. The @_ array contains what has been passed to the method - if the method is being called as a class method (like your constructor is) then the $_[0] will contain the class name, if it's an object method then it'll be the object itelf.

A => is very similar to a comma - essentially it is used to pass arguments by name - this is what the CGI methods generally do (this includes the constructor). Both sides of the => are in the @_ in the order they were passed - but the best thing to do after getting the class or object shifted out of @_ is to assign the whole array to a hash, and use it that way.

Hope this helsps

Cheers,
Erik

In reply to Re: 'new' constructors by erikharrison
in thread 'new' constructors by emcb

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.