Bill Stennett wrote:
> Hi All
> 
> Can some tell me the correct way to create a PERL module that exports some
> global configuration symbols which are used by orhter modules and programs
> and include the 'use strict' statement.
> 
> The problem is that if I include the use strict; line in the module then I
> must declare all my symbols with my. If however I declare the symbols using
> my the values do not export correctly. For example, if I define a module as:
> 
> #######################################
> #!/usr/bin/perl -w
> 
> package mylib;
> 
> use Exporter(); # use the exported module to handle exporting symbols
> @ISA = qw(Exporter);
> @EXPORT_OK = qw( $valuetoexport );
> 
> $valuetoexport = 'abc';
> 
> return 1;
> ########################################

Try this version (no shebang line needed on modules) :

package mylib;

use strict;
use Exporter(); # use the exported module to handle exporting symbols

our @ISA = qw(Exporter);
our @EXPORT_OK = qw($valuetoexport);

our $valuetoexport = 'abc';

1;

> and access the value in a program as follows:
> 
> ########################################
> #!/usr/bin/perl -w
> use strict;
> use mylib qw ($valuetoexport);
> print "$valuetoexport\n";
> ########################################
> 
> then the value is passed to the importing program correctly. There is a
> warning when the the 'mylib' module compiles saying that '$valuetoexport is
> used only once possibly a typo'.
> 
> I want to include 'use strict' in the module definition but if I do that
> then @ISA, @EXPORT_OK and $valuetoexport are all thrown out as needing a
> package name. I tried including @ISA and @EXPORT_OK in a use vars statement
> and declaring $valuetoexport with 'my' but I could not get the value to
> export.
> 
> I suppose I could wrap the variables I wish to export into function calls in
> an OO style of approach. Any suggestions much appreciated.



-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to