in reply to Parsing variables from one file to another.
This sounds to me as if you really want one of the templating solutions for Perl, like Template Toolkit.
If you're bent on doing this yourself (this is one of the rites of passage of a Perl programmer), then look at perlre. Put all your template values into a hash and use a regular expression with the /e modifier:
my %template = ( apachectl => 'my_apachectl', dname => 'my_foo', ); open my $fh, '<', $apachectl_template or die "Failed to open '$apachectl_template': $!"; my $template = do { local $/; <$fh> }; $template =~ s/\$(\w+)/$template{$1} || $1/ge;
If you're hell-bent on substituting lexical variables, which is a fairly bad idea, you'll have to resort to eval, but I won't even show you how to exactly do this, as using a hash is much, much safer.
|
|---|