I've a lot of small scripts working with databases. I like to initialize those scripts from an INI-file using the BEGIN-block of my scripts:
BEGIN
{
my
(
$IniFile, $SectionName, $IniConfig, @ParamNames, $ParamName,
$IniValue
);
$IniFile = "RefPin.ini";
$SectionName = "DbAttr";
$IniConfig = new Config::IniFiles
(
-file => "$IniFile",
-default => "$SectionName"
);
@ParamNames = $IniConfig->Parameters($SectionName);
foreach $ParamName (@ParamNames)
{
$IniValue = $IniConfig->val($SectionName, $ParamName);
$DbAttr{$ParamName} = $IniValue;
}
}
That code work, so my quest for knowledge involves just the question: Smart? Silly? Outright braindead?