Greetings, Ô wise monks !
I come to you because of a mystery I'd like to unravel: The module import code doesn't work as I expected. So, as I'm thinking that it probably is a problem with my chair-keyboard interface, rather than with the language, I need your help.
So, there are these modules I have, the first one goes like this:
use utf8;
use Date::Manip;
use LogsMarcoPolo;
package LibOutils;
BEGIN {
require Exporter;
# set the version for version checking
our $VERSION = 1.00;
# Inherit from Exporter to export functions and variables
our @ISA = qw(Exporter);
# Functions and variables which are exported by default
our @EXPORT = qw(getDateDuJour getHeureActuelle getInfosSemaine ge
+tTailleRepertoire getInfosPartition getHashInfosContenuRepertoire dor
+mir);
# Functions and variables which can be optionally exported
our @EXPORT_OK = qw();
}
# Under this line are definitions of local variables, and the subs.
I also have another module, which goes like that:
use utf8;
use strict;
use warnings;
use Cwd; # Module "CORE"
use Encode;
use LibOutils qw(getHeureActuelle);
package LogsMarcoPolo;
BEGIN {
require Exporter;
# set the version for version checking
our $VERSION = 1.00;
# Inherit from Exporter to export functions and variables
our @ISA = qw(Exporter);
# Functions and variables which are exported by default
our @EXPORT = qw(setNomProgramme ouvreFichierPourLog assigneFluxPo
+urLog pushFlux popFlux init printAndLog);
# Functions and variables which can be optionally exported
our @EXPORT_OK = qw();
}
# Here are other definitions of variables and subs, which I removed fo
+r the sake of clarity
sub init {
my ($nomDuProgramme,
$pathLogGeneral,
$pathLogErreurs) = @_;
my $date = LibOutils::getDateDuJour(); # La date de l'appel à
+ init()
my $time = LibOutils::getHeureActuelle(); # L'heure de l'appel à
+ init()
$nomProgramme = $nomDuProgramme;
# Ouverture du flux pour STDOUT:
my $stdout = assigneFluxPourLog(*STDOUT);
# On l'ajoute à la liste de flux 'OUT':
pushFlux('OUT', $stdout);
# Ouverture du flux pour STDERR:
my $stderr = assigneFluxPourLog(*STDERR);
# On l'ajoute à la liste de flux 'ERR', et à la liste 'DUO':
pushFlux('ERR', $stderr);
pushFlux('DUO', $stderr);
if (defined $pathLogGeneral) {
my $plg = $pathLogGeneral;
$plg =~ s/<DATE>/$date/g;
$plg =~ s/<TIME>/$time/g;
my $logG = ouvreFichierPourLog($plg);
pushFlux('OUT', $logG);
pushFlux('DUO', $logG);
}
if (defined $pathLogErreurs) {
my $ple = $pathLogErreurs;
$ple =~ s/<DATE>/$date/g;
$ple =~ s/<TIME>/$time/g;
my $logE = ouvreFichierPourLog($ple);
pushFlux('ERR', $logE);
pushFlux('DUO', $logE);
}
}
Now, look at the second module: When, in the "init" sub, I call the getDateDuJour() and getHeureActuelle() functions with an explicit namespace, it works fine.
If I remove the prefix, it doesn't work, even for the function whose name I put in the "qw(...)" chain after the use.
Would a fellow monk know why ?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.