in reply to web form processing - efficiency question

I'm not sure I understand your reservations about hashes, or what you mean by "precomputing hash keys" and extra memory.

The only thing you lose by moving to a hash is the ordering of the keys, but you can get that back:

my $question = { descriptions => { m => "male", f => "female", o => "other" }, choices => [ qw/m f o/ ] }
Then to generate the HTML in the right order is not so bad (not that I'm a big fan of this -- you should be using a templating system anyway):
for my $choice ( @{ $question->{choices} } ) { my $text = $question->{descriptions}{$choice}; print qq[<option value="$choice">$text</option>\n]; }
And validating choices becomes trivial:
$valid = exists $question->{descriptions}{$answer};
Anyway, having an array of arrays, with inner arrays having just 2 items, is a good sign that a hash (or certainly a relation matrix) might be in order.

blokhead

Replies are listed 'Best First'.
Re: Re: web form processing - efficiency question
by nmerriweather (Friar) on May 07, 2004 at 01:10 UTC
    I never thought of that approach -- i'm going to give that a shot.

    I severly disliked every templating system I came across in the past few weeks -- so I decided to build my own. The only part i questioned so far was html select fields.
      did you also check out Template-Magic? its very simple to use and very flexible.

      for the form-data validation must of us use Data::FormValidator which is mature.
      ciao
      philipp
        saw both...

        i kinda liked elements from each, and cut/pasted code into a custom form class

        i mostly program in python now -- haven't touched perl in a while, but need to build something in mod_perl -- i'm building classes in a format i'm used to programming with in python

        I know that might sound nightmarish to some, except its a lot easier for me to roll my own code for certain elements than it is to adopt my approach to solutions into cpan modules