Greetings DeusVult,

I'm not sure how security-wise this may be, but I think it's better than running an eval of user-changable data. Give this a try and let me know what you think. I've assumed a few things here, and I've also made @file_contents so you can see some dummy file data.

#!/usr/bin/perl -w use strict; my @file_contents; $file_contents[0] = 'My name is $name.'; $file_contents[1] = 'I live in the city of $city.'; $file_contents[2] = '$city is in the state of $state.'; my $file_contents = join("\n", @file_contents); my %stuff_to_parse = ( name => 'Gryphon', city => 'Seattle', state => 'Washington' ); foreach (keys %stuff_to_parse) { $file_contents =~ s/\$$_\b/$stuff_to_parse{$_}/g; } @file_contents = split(/\n/, $file_contents); foreach (@file_contents) { print $_, "\n"; }

Does this help? Also, anyone out there: Can someone tell me if I made any security mistakes here? Also, the \b on the end of the search pattern could be altered to be a little more robust.

-Gryphon.


In reply to Re: Digging interpolation deeper by gryphon
in thread Digging interpolation deeper by DeusVult

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.