Here is a test that I set up that seems to be working, but I do not fully understand why. I removed the logging facility from module 1 and placed it into its own utility module. I'm confused in TestUtil.pm--why isn't redeclaring or reopening $LOG an issue? I assume the calls are entirely separate from each other? Even still, why are there no file conflicts?

test.pl
#!/usr/bin/perl use warnings; use strict; use TestMod1; use TestMod2; use TestUtil; print "in file.\n"; write_log('file');
TestMod1.pm
#!/usr/bin/perl package TestMod1; use warnings; use strict; use TestUtil; print "loaded Mod1\n"; write_log('Mod1'); 1;
TestMod2.pm
#!/usr/bin/perl package TestMod2; use warnings; use strict; use TestUtil; print "loaded Mod2\n"; write_log('Mod2'); 1;
TestUtil.pm
#!/usr/bin/perl package TestUtil; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(write_log); print "loading module TestUtil\n"; #our $LOG if not $LOG and print "LOG did not exist.\n"; our $LOG; open $LOG, '>', 'test.log' or die; print "\$LOG = $LOG\n"; sub write_log { my $string = shift; print $LOG "$string\n"; } 1;
test.log
Mod1 Mod2 file
screen output
loading module TestUtil $LOG = GLOB(0x4006fcd4) loaded Mod1 loaded Mod2 in file.

In reply to Re: Modules sharing? by eff_i_g
in thread Modules sharing? by eff_i_g

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.