Drock,
While there are several ways that you can get around creating a module and doing use Mymod, it's not really a wise thing to do for several reasons. The main reasons are:
- If you have a look at many of the modules on CPAN, they do a lot of strange, interesting, and sometimes evil things... internally. But since they are properly-built modules, the calling code doesn't have to worry about this. Scoping your variables properly will achieve most of this as well, but making the module is better.
- do "filename.pl" assumes you know the name and location of the file. use package works based on @INC, which you can change, and the package name, which you control. (Yes, the filename still comes into play, but it's a bit cleaner.) This means it works in Windows and Un*x, since you don't have to use system-specific paths/delimiters/conventions.
- It's kind of silly to circumvent use and require. They were designed to do what you want, and work well. C'mon! Everybody's doing it. You want to be cool, don't you? ;-)
Seriously, though, when you consider that h2xs does most of the prep work for you, making a module out of a sub is pretty much cut, paste, change a few things in the header, save, done.
--J
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.