I think you'd like to have a look at do, require, use and eval. They all basically do the same thing - execute some code. Now the way they do it is a bit different.

eval EXPR
When passed a scalar containing some code, eval evaluates it in the current context. That can be very nice. Of cource it does this at runtime, so its a little slow(as the code in the scalar is compiled at runtime). It also traps any errors that might pop up.

do FILE
This is the old way of including files. It basically slurps in the file, and evaluates it. However, the code in the file, cannot see lexical variables in your program(and I guess that lexicals in the included file is not visible in the main code either) It does some nifty things though. It searches @INC directories for the file, and as oposed to the next two commands, it compiles the code each time it is include - which is something you might want if you are using the file for configuration.

require FILE
Same as do, except a file is never loaded/compiled twice, and any errors in the file will raise an exception(your program is likely to die...)

use module list
This is almost exactly the same as the following code:

BEGIN { require module; import module list; }
Since its inside a BEGIN block, the module is included before your program has started to execute, and so any errors will be caught before you actually start doing anything. Which is neat....
I hope this helps.
GoldClaw

In reply to Re: How can I source other perl scripts from within a Perl script by goldclaw
in thread How can I source other perl scripts from within a Perl script by juo

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.