D
Dave Bakhash
I have a set of executable scripts, all written in Perl. This time,
however, I would like all of these scripts to obtain their globals
from a single, separate file. I would also like all of my Perl files
to use the `strict' pragma:
use strict;
which has been a requirement of mine since I started using Perl.
Here's how I thought to do it. Suppose I have a script, foo:
File: foo
#!/usr/bin/perl
package Foo;
use strict;
BEGIN { require "/path/to/Foo.pm"; }
print $BAR; # uses a global variable `$BAR' defined in Foo.pm
# code follows...
Now, the file Foo.pm will look like this:
File: Foo.pm
package Foo;
use strict;
our $BAR = 'BAR'; # global variable
1;
The problem is that having the `use strict;' in the `foo' executable
file is causing problems, and Perl is complaining:
Variable "$BAR" is not imported at ./foo line 6.
Global symbol "$BAR" requires explicit package name at ./foo line 6.
Execution of ./foo aborted due to compilation errors.
What am I missing? Is there a better way to do this? Is `our' the
wrong declaration to be using here?
thanks,
dave
however, I would like all of these scripts to obtain their globals
from a single, separate file. I would also like all of my Perl files
to use the `strict' pragma:
use strict;
which has been a requirement of mine since I started using Perl.
Here's how I thought to do it. Suppose I have a script, foo:
File: foo
#!/usr/bin/perl
package Foo;
use strict;
BEGIN { require "/path/to/Foo.pm"; }
print $BAR; # uses a global variable `$BAR' defined in Foo.pm
# code follows...
Now, the file Foo.pm will look like this:
File: Foo.pm
package Foo;
use strict;
our $BAR = 'BAR'; # global variable
1;
The problem is that having the `use strict;' in the `foo' executable
file is causing problems, and Perl is complaining:
Variable "$BAR" is not imported at ./foo line 6.
Global symbol "$BAR" requires explicit package name at ./foo line 6.
Execution of ./foo aborted due to compilation errors.
What am I missing? Is there a better way to do this? Is `our' the
wrong declaration to be using here?
thanks,
dave