#..................."~/test/DataBank.pm" package DataBank; + our @EXPORT_OK = qw( set_webpath get_scanpath get_findpath); my %webpaths = ( mypath => "", scanpath => "~/WebTabs/auto/htmlscan.0", findpath => "~/WebTabs/auto/htmlfilter.0" ); sub get_scanpath {return ($webpaths{"mypath"} || $webpaths{"scanpath"} +);} sub get_findpath {return ($webpaths{"mypath"} || $webpaths{"findpath"} +);} sub set_webpath { my $pathme = shift; unless (-f $pathme){$pathme = "";} $pathme ||= get_scanpath(); $webpaths{"mypath"} = $pathme; } #..................."~/test/Scanner.pm" package Scanner; ; our @EXPORT_OK = qw( postscan); use Importer 'SpecsGet' => qw( pathout ); sub webget {.........} # download heaps sub postscan { my $pathx = pathout(); print "\n$pathx\n\n"; } #..................."~/test/SpecsGet.pm" package SpecsGet; our @EXPORT_OK = qw( pathout); + use Importer 'DataBank' => qw( get_scanpath get_findpath ); sub pathout {return get_scanpath();} #..................."~/test/testme.pl" use Importer 'DataBank' => qw (set_webpath); use Importer 'Scanner' =>qw (postscan); use Cwd qw(getcwd cwd); set_webpath (getcwd()."/xxx"); #........................................# hours later postscan();
Given the 4 files above suitably 'stricted' etc & closed off properly:
#> perl testme.pl ==> "~/xxx" ... (as expected)Seems to function perfectly well, deploying DataBank.pm as a central store for 'modularised' semi-static specifications whose values may occasionally get changed by yet other modules. The problem I am having is not understanding exactly why it works so I can rely on it?
There are myriad net explanations of the seldom used "local", "our", & "package" scopings but very little on this "file" scoping that I (and maybe others) use extensively. If the "file"-scoped lexicals of DataBank.pm are forced to stay in scope throughout, what is doing the forcing with respect to scoping rules?
In reply to modular file scoping by Pstack
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |