A very good way to solve this problem is to move that common code off into a library that sits in package main. For example you might have a small module called Configuration::Bootstrap that will figure out your appropriate paths to your codebase and configuration, then loads Configuration. And Configuration in turn will load your config files, set standard global variables, process your command line, copy command line variables into global variables and declare them, etc. The result? Your starting configuration will look like this:
Sure, doing this means you have to have package main split across different files. It means that you have to use symbolic references. Etc, etc, etc. Lots of code smells.#! /usr/bin/perl use strict; use warnings; use Configuration::Bootstrap ( "help" => 0, "man" => 0, "database=s" => undef, # ... ); use Company::Database; use Company::Person; # PROGRAM HERE __END__ =head1 NAME progname - Describe your program here ...
But the smells are misleading you. This is actually a good thing to do, and it will make your codebase easier to work with. However when you do it, you'll see immediately why our would have been the wrong thing to do.
That said, this example notwithstanding, there aren't many cases where you want to split packages across files. However if you implement it, you'll find yourself using this one over and over again. :-)
In reply to Re^14: My globals are visable; but undef'ed
by tilly
in thread My globals are visable; but undef'ed
by Wiggins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |