Your question is not very clear to me but I will take a guess. You want users to be able to edit a config file to make simple substitutions in some stream of data.
#this is what the config file will look like...
#string to replace, replacement
fred, john
paul, pete
smelly, feet
#!/usr/bin/perl -w
# here is some code (untested)
use strict;
my $config="substit.cfg";
my $regex;
# setup our regexen
open CONF, $config or die "cant open config $!\n";
while (<CONF>) {
next if /^#/; # ignore comments
next if /^\s*$/; # and empties
chomp;
my ($replace, $with)=split /,\s*/;
$regex.="s/".$replace."/".$with."/;";
}
close CONF;
# apply them to the input stream
while (<>) {
eval $regex;
print;
}
This is of cource fraught with dangers, if you users start getting clever about what they put in the config file they can cause much trouble. You would probably want to limit them to some simple character sets, perhaps only allow \w\d\s with a line like next if /[^\w\d\s]/ when the config is read in
update
That last check for nasty charaters won't work unless you add the comma too ! next if /[^\w\d\s,]/
Cheers, R. |