At 09:51 AM 1/16/2003 -0500, [EMAIL PROTECTED] wrote:
"Hanes, Philipp" wrote:
> Probably not.
Hi Philipp, how're things?


That's a bummer.
TMTOWTDI becomes NCD -> No Can Do
If it is any consolation, it isn't Perl's fault. It is inherent in the nature of parent/child processes. The child cannot update the parent environment.


> What's the script like?

it's a hodgepodge of several scripts, actually.
each one is intended to support a specific tool,
setting environment variables, paths, etc.
We'd like to make them more intelligent, and
I figured perl would make it a lot easier,
especially since I don't know shell programming.
Oh well, guess I'll have to learn it.
You'll want to devise a "settings" subsystem. If your scripts run in multiple operating environments (DEV vs. TEST vs. PRODUCTION), you want to be able to specialize the settings without re-specifying everything from scratch. Btw, Perl syntax is excellent for this purpose. The module compilation system also lends a hand.

Example:

# Config.pm - Settings for the "Foo" system

package Foo::Config;

use vars qw( $HomeDir $LogDir $Foo %Baz @Bar );

BEGIN
{
$HomeDir = '/usr/local/foo';
$Foo = 'foo';
@Bar = ( qw(Foo Baz Bar) );
%Baz = { Foo => $Foo, Bar = \@Bar };
}

#--------------------------------------------------
# Override defaults with "local" settings file
#--------------------------------------------------

BEGIN
{
# Override $HomeDir and other Foo settings
my $cmmd = "$ENV{HOME}/.foorc";
if ( -e $cmmd )
{
my $rc = do( $cmmd );
if ( $@ ) {
die "Couldn't parse perl script $cmmd: $@";
}
if ( !defined( $rc ) ) {
die "Couldn't do file $cmmd: $!";
}

# The following logic doesn't work under
# some versions of mod_perl
# if ( $rc ) {
# die "Couldn't run perl script $cmmd: $rc";
# }
}
}

#--------------------------------------------------
# Fixed relative paths or things that cannot be localized
#--------------------------------------------------

BEGIN
{
$LogDir = "$HomeDir/logs";
}

1;

Your various modules and programs now just "use Foo::Config;" and can refer directly to variables $Foo::Config::LogDir, etc. Works great for letting programmers each run in their own work area while keeping the Config structure intact in all environments.

hth,
Charlie


_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to