in reply to using main package variables within a module
To get you code to work, you can do one of two thing.
1. Make $one a global. I don't like this idea, but it is there.
2. Use a typeglob so the variable is in scope. This is a much cleaner way to deal with the problem. To use a typeglob, you would change your code to look like this:
P.S. Why are you accessing vars in main anyway? You may want to reconsider your design to use an object and have your main script set parameters on that object. Or you should have the variable be in your package, and then export or typeglob it to main's name space.package Shop; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(db_connect); sub db_connect { *one = *main::one; print "Print - ",$one, " - from the Shop package\n"; } 1;
|
---|