As others have said, what you are trying to do can be done by config files, a simple regex or templates. There is no need to re-invent the wheel or make it square.

Another way is to control your deployment script with command line parameters: deploy.pl --script-name abc --location xyz/abc etc.

And then there are ... autotools (written in Perl I think) which can do variable substitutions to source file templates. I would not use it just for a small task. I am mentioning it because you may want to use it as your main deployment/installation framework and be able to do ./configure && make all && make container && make backup && make push-git. It requires a lot of work to get started with it. Does your use-case justify it?

Here is a skeleton just for the var-sub part (ripped from various sources on the net):

# configure.ac AC_INIT([helloprog],[1.0],[abc@xyz.com]) AM_INIT_AUTOMAKE MYVAR="1234abc" AC_SUBST(MYVAR) AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([myscript.pl]) AC_OUTPUT
# Makefile.am bin_SCRIPTS = myscript.pl

Edit (forgot the perl script to have vars substituted):

Edit2 (the name ends in .in denoting a template input, the .pl file will be produced from that. During the configure stage, not the make.):

# myscript.pl.in # all @MYVAR@ will be substituted by value in configure.ac file my $var = "@MYVAR@"; print "var is : $var\n";

bootstrap it using (just once):

aclocal && automake --gnu --add-missing && autoconf

and then:

./configure <params> && make all

When IT people hear autotools, they will almost certainly parrot cmake, gradlew, maven as in a monty pythons sketch. Alas they are serious. Only a true hacker's heart fills with adrenaline when finally reached the state of ./configure && make all. But can you handle it?

bw, bliako


In reply to Re: Prepocessing perl code / substing variables (kraken released!) by bliako
in thread Prepocessing perl code / substing variables by nataraj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.