To amplify a little on what others have said - and this is not said to evade your question - you should NOT be doing what your trying to do, which is sharing varibles across files of a project. To do that they must be globals, and that way lies madness.

To repeat what others have said, data sent back and forth should be done by passing parameters from the calling to the called (which will usually be transferrred into lexicals within the sub by something like my ( $p1, $parm2, $etc, ) = @_; and returning values from the called to calling.

By making the file with the subs in it a module, you avoid namespace pollution, which is to say that if the subroutines in a file need to share variables with each other, they are still separate from variables you have inadvertently named the same thing in other modules or in your main program.

And to answer your last question, use strict;

works on a lexical scope, which is to say the scope is between the ineermost containg braces, or, at most, the whole of the file, so yes, every file needs use strict.

Oh, and these 2 files do NOT work as given in the absence of use strict, if you think they do, you're confused. It is the scoping of the "my" variable that prevents the scripts from working, not the use of strict.

--Bob Niederman, http://bob-n.com

In reply to Re: 'use strict;' between libraries by bobn
in thread 'use strict;' between libraries by Massyn

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.