|Syntactic Confectionery Delight|
overview/tutorial on packages - creation and useby chexmix (Hermit)
|on Apr 21, 2007 at 17:51 UTC||Need Help??|
chexmix has asked for the wisdom of the Perl Monks concerning the following question:
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!