Perl Script to Read file and Modify.

Need Perl script to assist with the following:  I need to modify a configuration parameter file based on the environment it is to run on.  Ninety-eight percent of the file is static and does not change.  One definition is missing, and the hostname needs to be updated based on the environment configuration; other than that the file is static.  My plan is to use a file template, whereas 99% of the file is exactly as it should be and good to go; and then use a tag, i.e. “<hostname>” to denote what my global substitution.  I would like to read in my Oracle database network configuration file and updated it with added entry plus the actual hostname based on the host the script will be executed on.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What have you tried?
In what way is your code failing?
What errors does your code produce?

Please post your script and sample config file.

You could do something like this one liner:
perl -pe "s/<hostname>/$ENV{'COMPUTERNAME'}\nMISSING DATA/" < config.txt > config.cfg

Open in new window

sdrussAuthor Commented:
Can't do one-liner.  This need to be part of an existing script.  Not able to post the actual script.  

No code is failing as it doesn't exist yet. So there for no errors.
First you say it needs to be part of an existing script then you say the code doesn't exist.  That's contradictory.

Start by doing a search on for config and template to find relevant modules.  Then run some tests using one or more of those modules.  When you get stuck, post your short but complete test script that we can run to duplicate and troubleshoot the problem.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

sdrussAuthor Commented:
Don't want to argue.  If you don't want to help -don't.  New code I'm interested in adding doesn't exist.  I will not be able to post anything based on my work environment.  Posting anything from my environment is a show-stopper.  It that was the case I would have posted initially.
I don't want to argue either but if you're unwilling to spend a few minutes attempting to solve your problem, why should anyone else spend the time?  I don't ask that to be argumentative; it's a legitimate and honest question.

Here's a tested script.

use strict;
use warnings;
use Template;

my $vars = { hostname => $ENV{'hostname'} };
my $template = Template->new;
$template->process('config.tmpl', $vars);

Open in new window

The var in the template is:
[% hostname %]

The output defaults to going to STDOUT but you can send it to a file instead.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FYI, you can also use the Text::Template module which has fewer dependencies and the syntax is almost identical.
sdrussAuthor Commented:
My work environment is in a closed network by design, and this makes it difficult to share details.  Appreciate your help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.