in reply to Export global variables not working correctly

Package AAA
package AAA; use lib ('.'); use BBB; use Exporter 'import'; our @EXPORT = qw /$bbb/; our $bbb=BBB->new(); 1;
package BBB; use lib '.'; use AAA; use feature 'say'; sub new{ my $class=shift; my $self=bless {},$class; return $self; } sub hello{ my $self=shift; say 'hello'; } sub hello2{ my $self=shift; $b->hello(); }
main.pl
#!/usr/bin/env perl use strict; use warnings; use lib (','); use AAA; use BBB; $bbb->hello; 1;
I think if you try and execute AAA.pm you get an error because when AAA references BBB, but BBB references AAA and so execution goes back to AAA and BBB->new has not been defined at this point. If you put 'use AAA' at the bottom of BBB, now you can execute AAA.pm, though I'm not sure why you'd want to. main.pl still works as expected though.
package BBB; use lib '.'; use feature 'say'; sub new{ my $class=shift; my $self=bless {},$class; return $self; } sub hello{ my $self=shift; say 'hello'; } sub hello2{ my $self=shift; $b->hello(); } use AAA;
If you use correctly it works as expected. In one file this is the minimum I could change your code to make it work as I think you want..
package AAA; use parent('Exporter'); our @EXPORT=('$bbb'); our $bbb=BBB->new(); package BBB; use AAA; use feature 'say'; sub new{ my $class=shift; my $self=bless {},$class; return $self; } sub hello{ my $self=shift; say 'hello'; } sub hello2{ my $self=shift; #$b->hello(); #what is $b? $bbb->hello(); } package main; use AAA; $bbb->hello2();