Use a hash to store the substitution values from the one source. Then just sub 'em in. You don't give any information about the source of the values to use for replacements. So I made some assumptions for this quick demo.
#!/usr/bin/perl -w use strict; my %values; # Pretend we have an input file w/values while (<DATA>) { last if /TEMPLATE/; # needed here to separate demo data my ($key, $val) = split; $values{$key} = $val; } # Pretend we have an input file w/template my $template = join '', <DATA>; # Process the fields for my $key (keys %values) { $template =~ s/%$key%/$values{$key}/g; } # Show result print $template; __DATA__ name Roadrunner job running TEMPLATE Hello Mr. %name%. We hope you are good at %job%.
You will need to adapt this to make it more robust and to make it fit your need but this should give you the general idea.

For a more elegant approach to the substitution, replace entire process fields "for" loop with this: $template =~ s/%(\w+)%/$values{$1}/g;

If you are going to get serious about this, I suggest you look into one of the template modules.

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall


In reply to Re: Transfering Varriables by dvergin
in thread Transfering Varriables by £okì

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.