Re: LAMP - Program Design with Perl

From: ChrisO (ceo_at_nospam.on.net)
Date: 07/17/04


Date: Sat, 17 Jul 2004 03:17:01 GMT

Dieter wrote:
> Hi,
>
> here I'd like to ask for your advice how to
> generally code a certain task, not for the details.
>
> O.K.- I try to express myself clearly:
>
> * There's a HTML-form from which the user can choose
> many different options (about 15) simultanously in
> all possible combinations for a variable number of items
> (batch mode).
>
> So e.g. lets say, she can enter "apple, peach, cherry"
> and request "color, taste, shape, short description"
> out of a set of many other options.
>
> * The CGI-script constructs a statement, depending on the desired
> information and queries the MySQL database.
>
> * Depending on what kind of information was requested,
> the output from the database is formatted differentially
> (headers, linebreaks ... ) and sent to the user.
>
>
> Now, the system already runs fine just for a few options.
> But with a about 15 options in different combinations
> I don't want to end up with endless numbers of "if"-clauses.
>
> Do you know a elegant solution, how to manage all the
> different optional parameters ?
>
> The problem appears on three stages:
>
> * Parsing the POST data (request)
> * Constructing the query for the database
> * Handling the output
>
>
> Maybe there are Perl modules to faciliate this kind of task ?

I have to second Anno's suggestion that you look very hard at a
"dispatch table" setup using a hash. Very powerful stuff. You agreed
somewhat, but then I saw you spit out some more nested "if" constructs,
so I think it worthwhile to second Anno's suggestion on this method (eg.
dispatching).

Secondly, at the risk of further complicating things for you, if you are
willing to take the time to thoroughly understand it, an recent article
by Randal Schwartz may be helpful to you (from _Linux Magazine_, Feb 2004):

http://www.linux-mag.com/2004-02/perl_01.html

Also consider in your "web application mix" not only Class::Prototype
(mentioned in Randal's article), but maybe even CGI::Application, and I
can't even imagine doing a web application without HTML::Template. At
the very least, HTML::Template can help get your mind off the
presentation layer and it's "connection" to your logic and allow you to
just focus on your logic.

Aside from the hint about dispatch tables, the rest of my suggestions
require some familiarization with Perl beyond the beginning stages;
judge for yourself to what level of Perl prowess you would place
yourself. But the article above could be helpful to you. Certainly
your discussion reminded me of it.

-ceo



Relevant Pages

  • Re: Possible Problem with bind_param
    ... It looks like the DBD is treating your value as in integer. ... Perhaps the DBD looks at the first part of the string, and thinks, "here's a number, so I'll pass an integer type to the database engine". ... Suggestion: try adding a type attribute to the the bind_param call, forcing the value to treated as a CHAR type. ... I came across some funny behavior in Perl with the DBI package, ...
    (perl.dbi.users)
  • PostgreSQL and Customer Database
    ... I've been working on both SQL and Perl for a while now, ... get them all onto an SQL database, and be able to keep track of sales, as ... the database available to customers and potential customers, ...
    (perl.beginners)
  • Ways of ensuring integers in the database are seen as numbers in perl?
    ... I'd like my database returned integers to look like integers to Perl but they currently don't until I add 0 to them. ... The reason for this is that adding 0 to a Perl scalar seems to persuade Perl the scalar is an integer. ... $num as returned from database: ...
    (perl.dbi.users)
  • Re: How to access MS Access from Perl?
    ... if you were to later migrate to MS SQL Server or Oracle ... minimize your load on the database server's compiled procedure cache. ... On the other hand, if startup time for your perl script is an issue, and ... slightly preferable to the bulkier DBI + DBD::ODBC. ...
    (comp.lang.perl)
  • Re: Attempted Simultaneous Access causes "Could not lock file"
    ... storing it in my MSAccess database. ... I just wrote another test perl program and pasted in the massive SELECT ... >> I can have multiple perl programs writing to the database, ... > It probably needs exclusive access to the entire Table if it's modifying ...
    (microsoft.public.access.tablesdbdesign)