Script Configuration


I am not a fan of how most scripts are distributed such that they require one to modify the code to make changes to the appearance. Here is a simple solution to that potential problem. INI files are text files broken down into sections.

# undefined default configuration

$config{buttonType} = “pfreak.xml”;
$config{buttonWidth} = “300”; # values are being read as strings
$config{buttonColor} = “#ffccaa”; # gold

# user configuration – INI files must be valid

open(INI, “userconfig.ini”);

while ($item=<INI>) { #go line by line ignore [[section information]]
if ($item =~ /(.+?)=(.+?)/) {$config{$1}=”{$2}”; #all variables are strings here}
}

close(INI);

# management configuration –

open(INI, “OverrideConfig.ini”);

while ($item=<INI>) { #go line by line ignore [[section information]]
if ($item =~ /(.+?)=(.+?)/) {$config{$1}=”{$2}”; #all variables are strings here}
}

close(INI);

### variable limits internal to script.

# buttonWidth must be a number less than 300

$config{buttonWidth} = $config{buttonWidth} + 1; # converted a string into a number.

if ($config{buttonWidth} + 1 > 301) {$config{buttonWidth} = 301}

$config{buttonWidth} = $config{buttonWidth} – 1;

Advertisements

One response

  1. Very Interesting!
    Thank You!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: