in reply to Re: Export global variables not working correctly
in thread Export global variables not working correctly
package AAA; use 5.20.1; use lib ('.'); use BBB; use parent('Exporter'); our @EXPORT=('$bbb','$msg'); our $bbb=BBB->new(); return 1; package BBB; use 5.20.1; use lib '.'; use AAA; sub new{ my $class=shift; my $self=bless {},$class; return $self; } sub hello{ my $self=shift; say 'hello'; } sub hello2{ my $self=shift; $bbb->hello(); } return 1; package main; use 5.20.1; use lib ('.'); use AAA; $bbb->hello2(); perl test.pl Global symbol "$bbb" requires explicit package name at BBB.pm line 16. Compilation failed in require at AAA.pm line 4. BEGIN failed--compilation aborted at AAA.pm line 4. Compilation failed in require at test.pl line 4. BEGIN failed--compilation aborted at test.pl line 4.
variable $bbb is exported only to package main, not package BBB. I want to make $bbb global to any packages
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Export global variables not working correctly
by vinoth.ree (Monsignor) on Mar 06, 2015 at 06:18 UTC | |
by Anonymous Monk on Mar 06, 2015 at 06:33 UTC |