If you require foo.pl in that way it is as though you typed it right there. Don't forget that the file must evaluate true, so put a 1; after the last closing } at the end of the file.
Because you just typed the subs in foo.pl right there, then you call the subs within it as normal. so, if the sub dothis has been declared in foo.pl - just call it as usual - $rc = dothis( par1, par2 );
You can do all sorts of other stuff, but this is the most basic way of 'including' code from another file. I used this technique a few years back to build hte functional blocks of a large CGI based web-app. Based on the function selected from the menu I couild require the code for that group of functions and then pass the parameters that came back from the CGI.
You are now on the way to your first Perl module! Have fun and look at the documents here regarding modules, it is in fact veryt simple to make a custom module of your own which will make maintenance easier and help with issues of namespace. But that's for another time!
jdtoronto
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.