Yes, I can see that re-design is not an option for you at the moment, and I agree that modularising and adding use strict will aid both debugging and enhancement.
But why make it all so complicated? You can have lexical variables which are strict-compliant and still package-global — just use our instead of my:
# File: main.pl
#! perl
use Modern::Perl;
use Foo;
our $Id = 42;
Foo::foo_id();
say 'In main, $Id is ', $Id;
...
# File: Foo.pm
package Foo;
use Modern::Perl;
sub foo_id
{
say 'In Foo, $main::Id is ', $main::Id;
$main::Id = 17;
}
1;
Output:
In Foo, $main::Id is 42
In main, $Id is 17
You can of course get fancier with @EXPORT, @EXPORT_OK, etc., but using the fully-qualified package names is probably a better strategy as it makes the trail of the global variables self-documenting.
Hope that helps,
|