H
Henry Law
I want an initialisation routine that will make a set of global
variables available to my perl application, read from a configuration
file. I'm going to use a package for this and I've chosen to code the
config in XML and use XML::Simple to read it in.
My problem is that perl doesn't find my package, while it finds
others.
My package is called "Global.pm". It looks like this
-------------------------------------------
package Global;
use 5.008;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw(
$g_one $stagedir
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
our $VERSION = '0.01';
our $g_one = 100;
our $stagedir;
my $xml;
use XML::Simple;
$xml = XMLin("NFConfig.XML");
$stagedir = $xml -> {stagedir}; # XML has <stagedir>xxx</stagedir>
1;
-------------------------------------------
"tryit", a test program to call Global, looks like this:
#! /usr/bin/perl -w
# Try out my "Global" package
use strict;
use warnings;
use Global ':all';
use XML::Simple;
# Print two of Global's exported variables
print "Global value \$g_one: $g_one\n";
print "Stage dir: $stagedir\n";
# Let's try XML::Simple native
my $xml = XMLin("NFConfig.XML");
# XML file has <testing>test value</testing.
print "Testing: $xml->{testing}\n";
-------------------------------------------
It's also important to know that XML::Simple is not installed in @INC;
just for now Simple.pm is in a subdirectory XML from the working
directory in which Global.pm and "tryit" live. I have verified that
@INC contains ".".
Now the problem that I need help with:
As set out above, "tryit" works fine, producing this
[henry@neptune henry]$ ./tryit
Global value $g_one: 100
Stage dir: F:\$User\PC\NFBack\Work
Testing: Test value
In other words "Global.pm" is found in the working directory, and
XML::Simple has been found by getting "Simple.pm" from the "XML"
sub-directory, both from the test program "tryit" and from the Global
package.
In practice I don't want Global.pm in the working directory; I want to
put it in a sub-directory called "NFB". Since XML::Simple can be
found by looking for Simple.pm in ./XML, I reasoned that Global.pm in
../NFB would be found by writing "use NFB::Global;". But no:
[henry@neptune henry]$ grep NFB tryit
use NFB::Global ':all';
[henry@neptune henry]$ find -name Global.pm
../NFB/Global.pm
[henry@neptune henry]$ ./tryit
Global symbol "$g_one" requires explicit package name at ./tryit line
11.
Global symbol "$stagedir" requires explicit package name at ./tryit
line 12.
Execution of ./tryit aborted due to compilation errors.
Perl version is "revision 5.0 version 8 subversion 0". OS is RedHat 9
(despite the presence of backslashes in the file name above).
Can someone point out what I'm doing wrong, or tell me which bit of
perldoc would enlighten me?
Henry Law <>< Manchester, England
variables available to my perl application, read from a configuration
file. I'm going to use a package for this and I've chosen to code the
config in XML and use XML::Simple to read it in.
My problem is that perl doesn't find my package, while it finds
others.
My package is called "Global.pm". It looks like this
-------------------------------------------
package Global;
use 5.008;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw(
$g_one $stagedir
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
our $VERSION = '0.01';
our $g_one = 100;
our $stagedir;
my $xml;
use XML::Simple;
$xml = XMLin("NFConfig.XML");
$stagedir = $xml -> {stagedir}; # XML has <stagedir>xxx</stagedir>
1;
-------------------------------------------
"tryit", a test program to call Global, looks like this:
#! /usr/bin/perl -w
# Try out my "Global" package
use strict;
use warnings;
use Global ':all';
use XML::Simple;
# Print two of Global's exported variables
print "Global value \$g_one: $g_one\n";
print "Stage dir: $stagedir\n";
# Let's try XML::Simple native
my $xml = XMLin("NFConfig.XML");
# XML file has <testing>test value</testing.
print "Testing: $xml->{testing}\n";
-------------------------------------------
It's also important to know that XML::Simple is not installed in @INC;
just for now Simple.pm is in a subdirectory XML from the working
directory in which Global.pm and "tryit" live. I have verified that
@INC contains ".".
Now the problem that I need help with:
As set out above, "tryit" works fine, producing this
[henry@neptune henry]$ ./tryit
Global value $g_one: 100
Stage dir: F:\$User\PC\NFBack\Work
Testing: Test value
In other words "Global.pm" is found in the working directory, and
XML::Simple has been found by getting "Simple.pm" from the "XML"
sub-directory, both from the test program "tryit" and from the Global
package.
In practice I don't want Global.pm in the working directory; I want to
put it in a sub-directory called "NFB". Since XML::Simple can be
found by looking for Simple.pm in ./XML, I reasoned that Global.pm in
../NFB would be found by writing "use NFB::Global;". But no:
[henry@neptune henry]$ grep NFB tryit
use NFB::Global ':all';
[henry@neptune henry]$ find -name Global.pm
../NFB/Global.pm
[henry@neptune henry]$ ./tryit
Global symbol "$g_one" requires explicit package name at ./tryit line
11.
Global symbol "$stagedir" requires explicit package name at ./tryit
line 12.
Execution of ./tryit aborted due to compilation errors.
Perl version is "revision 5.0 version 8 subversion 0". OS is RedHat 9
(despite the presence of backslashes in the file name above).
Can someone point out what I'm doing wrong, or tell me which bit of
perldoc would enlighten me?
Henry Law <>< Manchester, England