in reply to Set a variable in calling package
Exporter is capable of exporting variables as well as subs.
Is there a reason you aren't just exporting your $var, which would make it a member of both namespaces?
In prog.pl:
In MyModule.pm:#!/usr/bin/env perl use strict; use warnings; use 5.010; use lib '.'; use MyModule; my_sub; say "Main program: $var";
Result:package MyModule; use strict; use warnings; use 5.010; use base 'Exporter'; our $var; our @EXPORT = qw( my_sub $var ); sub my_sub { $var = 42; say "Set \$var to $var in my_sub"; }
$ ./prog.pl Set $var to 42 in my_sub Main program: 42
|
|---|