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


HI monks,
I have a scenario in which i have to generate "dynamic html".
I have data in the form of
Router Interfaces
aab.dsd.ll.com 138.196.122.11,138.196.122.12 etc
First question : i am making a reporting package for bandwitdh utilization in which i will be using mysql to store the data
1 Should i store the above data in a table ?
If anyone adds a new row to my table then i want that routername to get added to the list on the first html page and on clicking it there should be a page showing all interfaces of that router.(click on any one of them and the respective graph appears).
2 or should i just store it in a text file as router,interface1,interface 2 .
Or maybe i could just store in a hash in the script but that wont provide easy config to the maintainer.
More importantly 3 is there any module or technique to generate html on the fly
as soon as someone adds an entry to th db or file the webpage should show the extra links.
I know one way : Read file or db(DBI) ,parse data and then output html for them .But it is ungainly an mixes html and perl code.
Any suggestions?
Regards,
Chimni

Replies are listed 'Best First'.
Re: Generating dynamic html
by BUU (Prior) on Jan 20, 2004 at 10:20 UTC
    A) Sure, store it in a database. It might be over kill now, but it probably won't do any harm and it makes it very expandable/scalable.

    B) Write a perl script that grabs the data from the database and outputs the html (unless you have extreme usage requirements/processin g involved). As for mixing html and perl, use HTML::Template to avoid that.

    C) If you have the appropiate database (oracle maybe?) you might be able to add a 'stored procedure' that lets you generate the html every time a row is added, but most databases won't let you, as far as I know. Your other options are to either make an interface for inserting rows which will kick off the html generation or a cron job.
Re: Generating dynamic html
by Anonymous Monk on Jan 20, 2004 at 19:18 UTC
    I would write a small script using the CGI module.

    use CGI qw(:all);

    Also use the DBI, to access the database.

    Your scirpt is launched,
    if there are no arguments then print a list of all routers, all routers in list are a link back to this script like script.pl?router_name=aab.dsd.11.com
    if there is an argument (router_name) then list all interfaces for that router.

    simple enough just get CGI, and DBI, and look into how to use them.

Re: Generating dynamic html
by castaway (Parson) on Jan 21, 2004 at 23:21 UTC
    You question isnt very clear at all, nor is the data. Im assuming you have more than just a list of interfaces. If you have several pieces of similar and interrelated dynamic data to store, yes, use a database. If its not really, or all that dynamic, dont bother.

    There are several HTML templating modules, HTML::Template, Template Toolkit, at least one of those has a DBI plugin, as far as I know, so you can just throw it a statement object/result, and have it loop around the list of interfaces, outputting them.

    (No idea why you asked me specifically for an answer on this.. HTML aint my ting.)

    C.