The only thing you lose by moving to a hash is the ordering of the keys, but you can get that back:
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):my $question = { descriptions => { m => "male", f => "female", o => "other" }, choices => [ qw/m f o/ ] }
And validating choices becomes trivial:for my $choice ( @{ $question->{choices} } ) { my $text = $question->{descriptions}{$choice}; print qq[<option value="$choice">$text</option>\n]; }
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.$valid = exists $question->{descriptions}{$answer};
blokhead
In reply to Re: web form processing - efficiency question
by blokhead
in thread web form processing - efficiency question
by nmerriweather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |