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

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on how to generate html with perl and design pagination without query database

Replies are listed 'Best First'.
Re: how to generate html with perl and design pagination without query database
by davido (Cardinal) on Sep 25, 2006 at 06:16 UTC

    HTML isn't all that mysterious, it's just plain text laced with tags that are also based on plain text. For example, <a href = "somelink"> text </a> is all based on simple text. For a script to output HTML, it just needs to print. If you want to output the above HTML, you would do this:

    print '<a href = "somelink"> text </a>', "\n";

    If you're parsing CGI input (GET and POST data), that's often done using CGI. The same module also provides helper functions for generating HTML code, though for lightweight solutions I prefer just printing it, and for heavy-weight solutions, a templating system is probably better. Tools like HTML::Mason allow you to easily separate the content and HTML from the script's code, which usually improves maintainability and reduces development time for more complex dynamic websites.

    As for querying from a database, the Perlish way is to use the DBI module, along with the appropriate DBD (database driver) module. To be more specific, we would need to know what database you're querying and what you wish to query from the DB.

    Logins can be handled a number of ways. There's simple .htaccess provided by the webserver, and more elaborate schemes as well. It's all dependant on what you want and need. Session management is often handled by CGI::Session and its companion modules.

    Another approach to CGI programming is through CGI::Application. This module is intended to be subclassed, as the building blocks to your own object-oriented CGI application.

    Pagination is simply a matter of keeping track of how much content you plan to output, and deciding how much of that content you wish to put on a given page. There's not much to say there. If you've got content of 10000 characters, maybe you would want to divide the content into pages of 2000 characters instead. If that's a challenge, you've got some reading to do before you should even be considering handling things like website logins and database queries. Learning Perl, published by O'Reilly & Associates (the Llama book) is a great place to start for learning about Perl.

    For CGI strategies and discussion, I happen to like the Mouse book, CGI Programming with Perl, Second Edition, also published by O'Reilly & Associates. If dealing with CGI is kind of new to you, the book will really be helpful. Not that CGI is terribly complex, but until you've gotten the big picture, it's easy to stab away in the dark never quite hitting the mark.

    I hope this helps to point you in the right direction.


    Dave

Re: how to generate html with perl and design pagination without query database
by chargrill (Parson) on Sep 25, 2006 at 05:53 UTC

    For your first question, try this:

    open $fh, '>', 'somefile.html' or die "Can't open HTML file - $!"; #... do things here to generate $somestuff print $fh $somestuff;

    For your other question, you'll need to give us more to go on than "how do i degsin (sic) the out result for pagination".

    Oh, and as for the advice you seek, I advise you to read How (Not) To Ask A Question.



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
Re: how to generate html with perl and design pagination without query database
by dorward (Curate) on Sep 25, 2006 at 09:54 UTC

    Pagination is handled in almost exactly the same way as it would be if you were hitting the database every time. The differences are:

    • You do it in response to an event other than "The page was requested"
    • The URL will point to a static file (so probably page_4.html instead of paging.cgi?page=4)