in reply to How to share the global variables between two modules by using Perl CLI Framework?

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).
  • Comment on Re: How to share the global variables between two modules by using Perl CLI Framework?
  • Select or Download Code