Hi!

I have some script (i.e. backup script) that should work in different containers, do same job, but use different parameters in each container...

like

my $name = "my_second_project"; my $dir="/srv/msp"; do_backup($name,$dir); #this actually some pages of code

I want to put this script into git, so I do not know how to deal with paramethers that should be different in each container...

My idea was to change values to some substitution instructions and use some preprocessor that will do the substitution. Like

my $name = "%%NAME%%"; my $dir="%%DIR%%"; do_backup($name,$dir); #this actually some pages of code

and then create a small deploy script that has container specific configuration and just do preprocessing and installation. Like

do_preprocess("my_scripl.PL","/srv/msp/my_script.pl",{NAME=>"my_second_project",DIR=>"/srv/msp"});

So whenever I update my backup script and put it to git I can just git pull at the container, and run this installation script, and everything will continue working as before, but with new script version.

For variable substitution it is good to use some standard module. I guess I am not the first person who needs this. I carefully looked at the modules listed at https://metacpan.org/pod/distribution/Text-PerlPP/bin/perlpp in section ALTERNATIVES, but I did not like any of them. They are too old, or too new, part of some other project that have nothing in common with var substitution. These modules are not used in other modules and they are not part of debian (that is bad for me too)

Theoretically I can write Text::YetAnotherPP but there is a chance to get another unsupported module this way...

What is the right way to deal with my simple task? What would you advice?


In reply to 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.