kovacsbv has asked for the wisdom of the Perl Monks concerning the following question:
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:
How do I get Log() imported into main? TIA$ perl app.pl Undefined subroutine &main::Log called at app.pl line 8. $
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PERL modules named differently than the package won't export
by Eliya (Vicar) on May 14, 2012 at 16:48 UTC | |
by kovacsbv (Novice) on May 15, 2012 at 16:44 UTC | |
|
Re: PERL modules named differently than the package won't export
by dsheroh (Monsignor) on May 15, 2012 at 10:00 UTC | |
by kovacsbv (Novice) on May 15, 2012 at 13:59 UTC | |
by kovacsbv (Novice) on May 15, 2012 at 16:40 UTC | |
by dsheroh (Monsignor) on May 16, 2012 at 07:32 UTC |