Anish Kumar K. wrote:
I am in process of creating a template Say a HTML
template...pasting one sample line below.

<td width="1" bgcolor="#[%topColor%]"><img border="0" src="[%1x1_image%]" width="1" height="100%"></td>

and there is one text file(config.txt) has several entries

1x1_image=/images/temp_white.gif
topColor=FFFFFF

You can store config.txt in a hash and use the s/// operator:

    my %tmpl_vars = (
        '1x1_image' => '/images/temp_white.gif',
        topColor    => 'FFFFFF',
    );

    for (@data) {
        s{\[%([^%\]\s]+)%\]}
         { $tmpl_vars{$1} or die "Unknown tmpl var: [\%$1\%]\n" }eg;
    }

The /g modifier allows for multiple substitutions at each line.

As long as it is as simple as you have described here, this approach
is sufficient IMO. For a more advanced template system, I'd go for one
of the template modules.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to