Hello, Monks:

I am new-ish to Perl, and also have great gaping holes in my general programming knowledge due to an overlong detour in the arts. I am searching for a newbie-level intro to the topic of Perl packages, e.g. what uses they serve, how to create one, etc., really basic stuff like that.

The fact that I am posting typically means I will discover the answer to this myself in about five minutes and get really embarrassed, but ... I didn't find anything obvious on the Tutorials page here, and the obvious place in the docs (perlmod) begins kinda in medias res, thusly, about packages:

"Perl provides a mechanism for alternative namespaces to protect packages from stomping on each other's variables. In fact, there's really no such thing as a global variable in Perl."

OK. But what are packages, why would I want to create one and what can I put in one?

To get more specific about this: I am an amateur astronomer and am trying to focus my maturing Perl-ing by playing with astronomical data ... if I have (say - a simplistic example) a big long hash that maps IAU abbreviations for constellation names to their full names, can I pull that aside into a package so that it doesn't obscure the program or script that needs it?

Pointers to tutorials are welcome. Thanks!

UPDATE: while it is often said there are no stupid questions, it did not take long for me to realize that this one was ill-considered, & that I should have dug more before posting it!


In reply to overview/tutorial on packages - creation and use by chexmix

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.