H
Henry Law
I have a main program and two packages. The first package loads up a
number of system-wide variables and exposes them to the program that
uses them. The second package has utility subroutines, some of which
need access to variables exposed by the first package. For example,
the log file name is a system-wide variable which is exposed as
"global" and in the "Utilities" package there's a routine that writes
log records.
I can't work out how to get the Utilities package to see the "global"
variables, despite reading perlmod fairly carefully; some pointers to
relevant bits of doc would be helpful.
This works, and shows that global variables are exposed:
----------------------------------------------------
#! C:\Perl\bin\Perl.exe
use strict;
use warnings;
use NFB::ClientGlobal(':all');
#use NFB::Utilities('logrec');
print "Log file name is $g_logfile\n";
----------------------------------------------------
F:\>tryit.pl
Log file name is F:\NFB\nfblog.txt
F:\>
I'm not going to paste in the whole of NFB::Utilities, but the key
lines are these:
sub logrec {
open (LOGFILE,">>main::$g_logfile") or die "etc..";
If I "use" it from the program above the error message is
Global symbol "$g_logfile" requires explicit package name at
NFB/Utilities.pm line 48.
In other words "logrec" is not seeing the definition of $g_logfile; as
you can see I have been experimenting with explicit package names -
including naming the "NFB::ClientGlobal" package that exposed the
$g_logfile variable in the first place, but all without success.
Coaching, please!
number of system-wide variables and exposes them to the program that
uses them. The second package has utility subroutines, some of which
need access to variables exposed by the first package. For example,
the log file name is a system-wide variable which is exposed as
"global" and in the "Utilities" package there's a routine that writes
log records.
I can't work out how to get the Utilities package to see the "global"
variables, despite reading perlmod fairly carefully; some pointers to
relevant bits of doc would be helpful.
This works, and shows that global variables are exposed:
----------------------------------------------------
#! C:\Perl\bin\Perl.exe
use strict;
use warnings;
use NFB::ClientGlobal(':all');
#use NFB::Utilities('logrec');
print "Log file name is $g_logfile\n";
----------------------------------------------------
F:\>tryit.pl
Log file name is F:\NFB\nfblog.txt
F:\>
I'm not going to paste in the whole of NFB::Utilities, but the key
lines are these:
sub logrec {
open (LOGFILE,">>main::$g_logfile") or die "etc..";
If I "use" it from the program above the error message is
Global symbol "$g_logfile" requires explicit package name at
NFB/Utilities.pm line 48.
In other words "logrec" is not seeing the definition of $g_logfile; as
you can see I have been experimenting with explicit package names -
including naming the "NFB::ClientGlobal" package that exposed the
$g_logfile variable in the first place, but all without success.
Coaching, please!