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();

In reply to Re: Export global variables not working correctly by trippledubs
in thread Export global variables not working correctly by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.