Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have general, high level question concerning HTML and Perl. I have a lot of html pages with tables etc that I designed in Dreamweaver. I have a mysql db and perl scripts that extract data from the database. Now I need to take the data and insert it into the tables in the html.

What do people recommend as the best method to do that? I see two options. One is to use print statements in the perl script that prints out all the html and the data. This could get quite messy with all the tags and having to escape certain characters etc:  print ("<HTML><BODY><TABLE><TR>..etc")The one problem I see with this method is that when I alter the page in dreamweaver I have to repaste the code into the perl script.

The other option, which I have used before, is to place tag holders in the HTML page in dreamweaver. For instance whereever I want the date to appear I put something like %Date%. Then I open the html page in perl and parse the page looking for these special tags. Wherever I find the tag I replace it with data from the db.

What do people think of these two methods or is there a better way to go about what I'm trying to do? Thanks.

Replies are listed 'Best First'.
Re: Printing HTML
by Zaxo (Archbishop) on Jun 23, 2002 at 22:49 UTC

    Template Toolkit or HTML::Template will provide capabilities much like what you are used to, but with Perl power behind 'em :)

    Both modules have been the subject of Tutorials and Notes here. I've tried the first option you mentioned, dont go there!

    After Compline,
    Zaxo

(jeffa) Re: Printing HTML
by jeffa (Bishop) on Jun 23, 2002 at 23:41 UTC
    Being a big fan of HTML::Template, i took the time to develop some very simple extensions for Dreamweaver. You can get them here.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Printing HTML
by Chmrr (Vicar) on Jun 24, 2002 at 03:32 UTC

    Several people have mentioned their favorite templating tools, but I thought I'd throw out something perhaps more useful -- specifically, how to choose a templating system. I shan't muddy the waters by mentioning my favorite, of course. *grin*

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Re: Printing HTML
by inblosam (Monk) on Jun 23, 2002 at 23:53 UTC
    You may want to also look into HTML-Embperl. I have not had to use it myself, however. I have seen it recommended here and there on perlmonks.

    Michael Jensen
    michael at inshift.com
    http://www.inshift.com
Re: Printing HTML
by aersoy (Scribe) on Jun 23, 2002 at 22:53 UTC

    Hello,

    This sounded to me like you are looking for a templating solution. Please take a look at Text::Template

    I hope this helps.

    --
    Alper Ersoy

Re: Printing HTML
by fenonn (Chaplain) on Jun 23, 2002 at 22:56 UTC
    Take a look at HTML::Template off of CPAN. That should be able to do what you want.