in reply to search and variable interpolation in templates

Greetings. I'm assuming that the variables you want to place in the "update" sections are stored in arrays, and that all arrays are the same length...

# @vars, @this, @doing, @dink are predefined. print "<h1>Some beginning HTML up here</h1>\n\n"; for ($x=0; $x<$#vars; $x++) { print "interpolate $vars[$x] when they are<p>\n"; print "between brackets like $this[$x].<p>\n"; print "<a href="$doink[$x]">$dink[$x]</a>\n"; } print "<small>The ending HTML down here</small>\n";

Is this what you're looking for? This will change significantly if you want to hold your data in something other than these arrays like a hash or something (which would be recommended). Anyway, let me know if this doesn't help; I'll expand my answer or add something. I do this sort of thing all the time with CGIs.

--Gryphon.

Replies are listed 'Best First'.
Re: Re: search and variable interpolation in templates
by ColonelPanic (Friar) on Jan 30, 2001 at 23:11 UTC
    Sorry if I wasn't clear in my original question. I have an HTML template in an external file. Hard-coding it in like that would defeat the purpose of having a template. I want non Perlers to be able to edit the HTML without (gasp!) seeing any code.

    When's the last time you used duct tape on a duct? --Larry Wall
Re: Re: search and variable interpolation in templates
by thealienz1 (Pilgrim) on Jan 30, 2001 at 22:56 UTC

    Personally I would think this method would be best the best because then it doesn't have to replace variables in a string by searching, but just printing them when called for. Of course I could be wrong and just amde an ass of myself.

    I'm not saying I'm the best at Perl, but I'm saying that I am the best.