Hi, all:

I have different versions of a module, say Utils1.pm and Utils2.pm with different filenames but they all have the same package name. I want a .pl file to be able to use whatever version it wants.

Here's the module:

package Utils; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(Log); # symbols to export on request sub Log { my $message = shift; print STDERR "$message\n"; } # Note that Log() is also called from the Utils namespace: sub Start_app { Log("App started."); # Handle other stuff } 1;

And it exports a few functions that are used at many points int the code. Because the function is used so many places, I want to improve readability by not explicitly referencing the package in app.pl.

Then we have the app.pl:

#This file: app.pl use strict; use warnings; use Utils1; Log("App started");

But I get this when running it:

$ perl app.pl Undefined subroutine &main::Log called at app.pl line 8. $
How do I get Log() imported into main? TIA

In reply to PERL modules named differently than the package won't export by kovacsbv

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.