in reply to Pass data to a Module
But sometimes it makes sense to export globals. If you want to, just follow the following template in your module:
And now in your client script do:package My::Module; use base 'Exporter'; @EXPORT_OK = qw( $foo some_sub @stuff ); use strict; use vars qw($foo @stuff); # Write your module here, using your variables and # defining functions for export. 1;
Material you may want to look up. strict.pm and relatives for explanations of the sanity checks, Exporter is being used to export from one package to another, and Dominus' Coping With Scoping to understand why the variables were not being seen as shared in the first place.use strict; use My::Module qw($foo some_sub @stuff); use vars qw($foo @stuff); # etc
|
|---|