If you're not sure about the specifics of creating a module, an intermediate step is to put it in a 'library.' This just means you stick the sub into a separate file and put a 1; at the end of the file. Then, in all of your programs, add a 'require' statement and point to the library file. Then the sub will be available to the program. This is one step away from creating an actual module, but it removes the package and Exporter issues. There is an example
here.
When you convert it to a shared sub, you may want to consider using named parameters when you pass in variables. This makes it much easier to change things in the future without breaking a bunch of code that is relying on the position of passed in variables.
There is a good section on named parameters in Effective Perl Programming. Basically, you pass a hash into the sub rather than an array and pull the parameters off as a hash.
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.