Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Program to EXE - Can it still be configured using require?

Status
Not open for further replies.

Kenny100

Technical User
Feb 6, 2001
72
NZ
Hi Folks

I've written a small Perl program that I'd like to release as freeware. It is configurable by changing variable values in a separate file called 'config.txt'. This is read into the Perl program using 'require "config.txt";'.

However, before I let the program loose onto the web I'd like to turn the Perl program into an .exe (or similar) as this allows it to be run without requiring the Perl compiler. I used a program called perl2exe and it worked fine. However, changes to config.txt no longer alter the exe program. I realise that this has something to do with the fact that the code has been compiled and is therefore no longer configurable.

Is there another way around this? How can I make my program executable but still continue to be able to change it's functionality by changing variables in config.txt?

Cheers,
Kenny.
 
You can just read it in from a text file. Example:

config.txt
Code:
path=c:\program files\blizzard\diablo
command=del *.*

myScript.pl
Code:
use strict;
use warnings;

open FILE, &quot;<config.txt&quot; or die &quot;unable to open config.txt : $!&quot;;
my %config;
while(<FILE>)
{
  chomp;
  my ($name,$value) = split /=/;
  $config{$name} = $value;
}
close FILE;
die &quot;Bad config&quot; unless(exists $config{path} && exists $config{command});
chdir $config{path} or die &quot;Unable to change working directory: $!&quot;;
system $config{command};
This is just a goofy example at one way to remove a method of personal destruction from one's machine, but it illustrates the idea. You open a text file, read in the data you're looking for, remove the newline, assign it to a variable, close the file, and use it. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top