At risk of missing the point of the question you're asking - have you had a look at the module 'Exporter'? It's ... well, it's basically geared up to exporting (and importing) variables from modules.

Anyway, that aside - the reason you get those to errors, is because the module 'runs' when you import it. The print statements on like 63 and 75 aren't encapsulated within a subroutine, so they run at the same time as you import the module - which is before the 'init' subroutine is called.

You will get the same error with a blank script that just has the 'use' lines in it, I think.

#!/usr/bin/perl use strict; use warnings; package testfish; sub sub_to_do_something { print "Doing something \n"; } print "FISH\n"; 1;
And script:
#!/usr/bin/perl use strict; use warnings; use testfish; print "Not done anything with the module yet\n"; &testfish::sub_to_do_something();
Gives an output of:
FISH Not done anything with the module yet Doing something
Which is more or less the same as you're doing with that 'print' line in your modules. Init hasn't been called yet. (I assume it's something that CLI::Framework requires and uses later).

In reply to Re: How to share the global variables between two modules by using Perl CLI Framework? by Preceptor
in thread How to share the global variables between two modules by using Perl CLI Framework? by ballstar

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.