
johnpc831
Novice
Dec 10, 2009, 3:38 PM
Post #4 of 4
(3865 views)
|
Re: [mehaboob] setting up variables so that i can use them in any other scripts
[In reply to]
|
Can't Post
|
|
Another popular way of doing this is creating a package that inherits from Exporter using
package MyPackage; use Exporter; @ISA = qw(Exporter); Then, within the package, you can specify a bunch of variables and values that will be used throughout your programs. You can then decide which variables and/or functions to export to any program using this package using the @EXPORT and @EXPORT_OK arrays. Example
@EXPORT = qw($variable1 $variable2 @list1 @list2); @EXPORT_OK = qw($variable3 $variable4 @list3 &myfunction); You can then use your package and have all the stuff specified in @EXPORT imported into your program automatically, or have all the stuff specified in @EXPORT_OK imported upon request. So if you only wanted $variable4, you would say
use MyPackage qw($variable4); The Exporter module is pretty neat, and it can do even more. You can even set up export tags to import groups of things into your program.
|