Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Best Perl Module for creating multiple web pages with different information in them?

by fraizerangus (Sexton)
on Feb 19, 2013 at 13:41 UTC ( #1019556=perlquestion: print w/ replies, xml ) Need Help??
fraizerangus has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

Just a general advice question more than anything, I need to create a website which links to a new web page, each has a unique picture and name such as something like this (http://www.molmovdb.org/cgi-bin/browse.cgi) and I was just wondering which module was best for doing this as the overall aesthetics of the pages needn't be that great I just need to create roughly 2,000 of them fairly quickly.

Many Thanks and Best Wishes

Comment on Best Perl Module for creating multiple web pages with different information in them?
Re: Best Perl Module for creating multiple web pages with different information in them?
by Anonymous Monk on Feb 19, 2013 at 13:49 UTC
Re: Best Perl Module for creating multiple web pages with different information in them?
by sundialsvc4 (Monsignor) on Feb 19, 2013 at 13:51 UTC
    If what you want to come up with is 2,000 pages of identically or consistently formatted content, then I say in all seriousness that you could use a word-processor to do that.   It is literally an off-shoot of using shell documents to spit out thousands of customized letters from a database.   There is also software out there, e.g. for static generation of on-line catalog pages.   Once the content has been created, you simply let Apache do what Apache already does with this collection of ordinary files.   No Perl or any other sort of programming would be involved.

    It’s real easy to look at a task and to jump to a conclusion as to how to get it done.   My guess is that this is what you have inadvertently done here.   Static pages, statically generated by means of an existing tool, are then statically served up.   Finis.

      Seriously, suggesting a word processor over some scripting for this task? IMHO this advice isn't ideal, what if they have to make a change, for example add/edit/remove something, your suggestion would mean editing the files again. This is a maintenance nightmare, and a very time consuming, boring repetitive task, you know, the stuff computers are much better than humans at doing?

      Update: fixed typo.

        Heard of "mail merge"?

        package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: Best Perl Module for creating multiple web pages with different information in them?
by marto (Chancellor) on Feb 19, 2013 at 14:18 UTC
Re: Best Perl Module for creating multiple web pages with different information in them?
by tmharish (Friar) on Feb 19, 2013 at 14:31 UTC
    You could also use Catalyst its a MVC Web Application Framework.
Re: Best Perl Module for creating multiple web pages with different information in them?
by blue_cowdawg (Monsignor) on Feb 19, 2013 at 15:13 UTC
        Just a general advice question more than anything, I need to create a website which links to a new web page, each has a unique picture and name such as something like this (http://www.molmovdb.org/cgi-bin/browse.cgi)

    You don't give much to chew on with respect to why or what you are doing, but let me take a short in the dark on this:

    In my view there isn't a single CPAN module that will address your needs. That said I'd recommend you look at both CGI (if you're not already familiar with it) and HTML::Template.

    Consider the following mini-application:

    #!/usr/bin/perl -w ################################## # Filename: albuum.cgi ################################## # use strict; use CGI; use HTML::Template; use DBI; my $dbh = (mumble..muble...); # Put your connection logic here my $q = CGI->new(); my $pic_id = $q->param('pic_id'); if ( $pic_id ) { my $sth = $dbh->prepare(qq( select picture_path from photo_album where picture_id = ? ) ) or die $dbh->errstr; $sth->execute($pic_id) or die $sth->errstr; my ($path)= $sth->fetchrow_array; my $tmpl = HTML::Template->new(filename=>'picture_page.tmpl'); $tmpl->param(picture_path=>$path); print $q->header(),$q->start_html(),$tmpl->output(),$q->end_html; exit(0); } else { my $tmpl = HTML::Template->new(filename=>"show_album.tmpl"); my $sth= $dbh->prepare(qq( select picture_id,title,path from photo_album order by title )) or die $dbh->errstr(); $sth->executre(); my @pictures =(); my $count=0; my $table_row = []; while (my $row=fetchrow_hashref){ push @$table_row,$row; $count++; if($count > 2){ $count=0; push @pictures,{row=>[$table_row]}; $table_row = []; } } my @check_row = @$table_row; if ((scalar @check_row) > 0 ) { my $add_cols = 3 - (scalar @check_row); for(my $i=1;$i<=$add_cols;$i++){ push @$table_row,{picture_id=>"",title=>"",path=>"" }; # bl +ank cell! } push @pictures,{row=>[$table_row]}; } $tmpl->param(thumbnails=>[@pictures]); print $q->start_html,$tmpl->@output,$q->end_html; } exit(0);
    What this does is on entry to the application it goes to a database and queries for a list of your pictures and pulls in a template to produce HTML that displays a table of thumbnails. Here is your template code for that:
    /** show_album.tmpl **/ <table width="100%" border="1" align="center"> <TMPL_LOOP NAME=thumbnails > <tr> <TMPL_LOOP NAME=row> <td> <TMPL_IF NAME=picture_id> <form action="/cgi-bin/album.cgi"> <hidden name="pic_id" value="<TMPL_VAR NAME=picture_id>"> <img src="<TMPL_VAR NAME=path>" width="75"><br> <submit name="action" value="Pic Me!"> </TMPL_IF> </td> </TMPL_LOOP> </tr> </TMPL_LOOP>
    That will render a table of three cells per row with a thumbnail of the pictures in the album. Pressing the "Pic Me!" button beneath each picture will bring you to a page with the full sized picture.
    /** picture_page.tmpl **/ <p> <a href="/cgi-bin/album.cgi">&lt;lt;Back</a> </p> <div style="width: 80%; border outset 3px black; margin: auto;"> <img src="<TMPL_VAR NAME=path" style="margin: auto;"> </div>
    CAVEAT: This code was all written before I finished my first coffee and was not tested.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Best Perl Module for creating multiple web pages with different information in them?
by tobyink (Abbot) on Feb 19, 2013 at 17:17 UTC

    I've written a module called HTML::Inject which is designed for injection of small snippets of HTML into a template HTML file. For example

    use strict; use warnings; use HTML::Inject; use HTML::HTML5::Writer; my @pages = ( [ 'greeting.en.html', 'Hello' ], [ 'greeting.fr.html', 'Bonjour' ], [ 'greeting.es.html', 'Ola' ], [ 'greeting.de.html', 'Guten Tag' ], ); my $template = HTML::Inject->new(target => <<'TEMPLATE'); <html> <div id="content"> <h1 id="heading"></h1> <div id="footer">Copyright &copy; 2013 Toby Inkster</div> </div> </html> TEMPLATE my $output = HTML::HTML5::Writer->new(polyglot => 1); for my $page (@pages) { my ($filename, $title) = @$page; my $filled_in = $template -> inject_and_new("<title>$title</title>\n") -> inject ("<h1 id='heading'>$title</h1>\n"); open my $fh, '>', $filename; print $fh $output->document($filled_in); }
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
    pmsig

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1019556]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-09-18 05:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls