-----Original Message-----
From: Dan Anderson [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 21, 2004 2:30 PM
To: Andrew Gaffney
Cc: R. Bryant; [EMAIL PROTECTED]
Subject: Re: CGI.pm *with* a templating system?


On Wed, 2004-01-21 at 01:45, Andrew Gaffney wrote:
> Dan Anderson wrote:
> > On Tue, 2004-01-13 at 16:05, R. Bryant wrote:
> > 
> >>Hi List,
> >>
> >>Is it possible to use CGI.pm in conjunction with a templating 
> >>system?
> > 
> > 
> > Whenever you send out anything from your CGI object you'll do 
> > something like this, correct?
> > 
> > my $cgi = CGI->new;
> > print $cgi->header;
> > 
> > Well you're *printing* anything you send out.  So if you wanted to 
> > insert something between something else you would just print it.
> > 
> > However, I'm not quite sure this response is exactly what you're 
> > looking for.  I don't know of any templating systems off the top of 
> > my head that allow you to read in some template file and spit out 
> > some data. However, I would assume it would not be too hard to 
> > implement.
> 
> Back when I was writing CGI in C (my pre-Perl days), I would create an

> HTML file that
> contained %s, %d, etc. in place of where values should go. I would
then read in the file 
> to a variable. I would do something like:
> 
> printf($file_that_i_read, value1, value2, value3, value4, value5, 
> value6);
> 
> which worked fairly well. The only problem was that I had to 
> create/edit the HTML
> templated by hand because any HTML editor would try to escape my '%s'
and '%d'. Of course, 
> since I write my HTML by hand anyway, that's not really a problem ;)

>Perl's substitution regular expressions work great for that.  I often
use HTML templates where in a section for a table I'll put something
>like:
>##PUT#DATA#HERE##

>And regular expression s[##PUT#DATA#HERE##][$foo] where foo is what I'm
putting in works wonderfully.

>-Dan

In my HTML files I use [NAME] for the items I want to replace, then use
regular expressions to replace the tags. Code looks like this:

Open(INF, "filename.html");
@my_web_page = <INF>;
Close(INF);

Foreach $line(@my_web_page)
{
        $line =~ s/\[NAME\]/ $what_i_want_to_replace_it_with /g;
}

Print "@my_web_page";

Does the job just fine.













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


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 1/19/2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 1/19/2004
 


-- 
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