Why do you want to split the subroutines into files? If you want to "encapsulate" the elements (to ensure that, for example, global variables don't "leak" between routines) you can do that within a single file by putting things in blocks:

use strict; use vars ('$really_global_var'); { # First block, the main routine my($var_in_main); main(); exit(0); sub main { SubOne::sub1(); ... } } { # Second block for the first set of things # Can also put it in its own package for further # clarity package SubOne; my($sub1_var); sub sub1 { $::really_global_var = 42; $sub1_var = 23; } }

If you require a whole load of files then it makes it harder to ship. Of course if you have a number of scripts that each use subroutines then putting everything in one file won't work.


In reply to Re: Subroutines loaded in from ohter files by hawtin
in thread Subroutines loaded in from other files by Valerie170

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.