If you've used modules then you've used packages, they were just inside the module file rather than inside your main script. Putting them in the main script however as you have above is legal and useful if you want to break something off into a class (basically a package is a class) but its not all that big and you don't want to keep track of two files. Although your code above wouldn't do anything until you have a package main; and the other packages would have to be called.

The most common use of this method is when you have a tied variable or an AUTOLOAD. Also some modules make use of creating classes from the modules main classes. I've been using wxPerl lately and it makes a lot of sense to use this method there as the main window (wxPerl is a GUI library) has to have its own constructor method.

Hope that helps
Chris

Lobster Aliens Are attacking the world!

In reply to Re: Using a package into script by cfreak
in thread Using a package into script by nite_man

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.