Global variables from a module, while using strict



I have a module which is basically a about 50 global variables and about 2 methods.  Because I am ‘using’ strict, all of the variables are declared with ‘my’.

 

I in my scripts which use  the module, I can’t access any of the variables, though I can access the sub routines.

 

I looked at Exporter, but there are two problems with the examples I see.  One, they export the globals into the ‘main’ namespace, which I don’t want.  I want them to be accessable like this: Module::myGlobal.  The other examples show the importing script explicity importing every variable.  This would be very tedious.

 

Here is an example of what I want:

 

<Sam.pm>

#!perl -w

 

use strict;

package Sam;

 

my $string = "sam";

 

sub Str

{

            print "string = $string\n";

}

 

 

1;

</Sam.pm>

 

<samtest.pl>

#!perl -w

 

use strict;

use lib ".";

use Sam;

 

Sam::Str();

print "Sam::string  = $Sam::string\n"; #can't access $Sam::string here????

 

exit 0;

</samtest.pl>

 

Thanks,

 

~Shea M.



Relevant Pages

  • Newbie question: migrating "global variables" from ASP to ASP.NET
    ... We've been using ASP to power our companys intranet ever since around 1998, ... i.e. we'd like to migrate our existing ASP scripts to ... In 1998 we've put together a separate include-file containing all commonly ... Now I know that global variables are probably the second most stupid idea ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to get list of records since last time - through a script
    ... The most obvious thing to do is to define two global variables B and C - ... And to make two scripts, one which makes a query based on the A and B, ... the correct list layout. ...
    (comp.databases.filemaker)
  • How to get list of records since last time - through a script
    ... I'm trying to automate a process on a database. ... The most obvious thing to do is to define two global variables B and C - ... And to make two scripts, one which makes a query based on the A and B, ...
    (comp.databases.filemaker)
  • Re: Defining subfunctions in script M-file
    ... Avoid scripts anyway. ... I realized that I use quite a bit of scripts in my work. ... pulls it into its workspace. ... This is one of the same reasons why the use of global variables in functions ...
    (comp.soft-sys.matlab)
  • Re: Could /bin/sh function conceivably be used by multiple scripts?
    ... > I want to have a function which sets global variables. ... > which I have to edit in multiple scripts everytime I want to modify them ... > I don't want to edit this in many different scripts. ...
    (comp.unix.shell)