Ok, I have a script, in which I read from a text file, such as this:
open(FILE, "/home/user/template/$filename.txt"); while (<FILE>) { s/(\$[a-zA-Z0-9\{\'\}_]+)/ eval ($1) /ge; $template{'content'} .= $_; } close(FILE);
This reads every $string in the text file, and replaces it with the perl value of $string since it normally would not, because of it being in a text file and not read as a string by Perl.
It then puts that "value" into a hash.

That is my understanding, as limited as it is.

Here is my question.

What if that is in a database, and instead of it having $string it has {{string}} and I normally do a s/{{string}}/$string/g;

I'm getting a error doing it that way in a subroutine, because not every database value has the same {{stringname}} so I get a lot of "useless switch" errors.

So how do I get the database record to be in a value of <FILE> so that I can do it like my other one, except like this:
while(my ($db_name,$content,$_add_name) = $sth->fetchrow_array()) { s/\<templ_var ([a-zA-Z0-9\{\'\}_]+)\>/ eval ($1) /ge; s/{{([a-zA-Z0-9\{\'\}_]+)}}/ eval ($1) /ge; $_content = $_; if ($_add_name) { $_content = qq~<!--Start $db_name-->$_content<!--End $db_name- +->~; } $temp_vars{$db_name} = $_content; }

I hope I made this clear enough.
I would appreciate any tips or advice.
Thank you.

Richard

In reply to <FILE> Questions by powerhouse

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.