Greetings monks,

After many hours of frequent frustration and alliteration I decided to ask for your collective advice. Here is the skinny.

I have a form with about 30 form elements including 2 multiple selects (location and domain). This form uses the method get. My script is to use CGI.pm to parse the data from CGI. I test each param from my form to create a single where statement, $where. This is use to create an SQL select statment. An example of the select statement could be, "SELECT * from mytable where server LIKE %someserv% AND (location = 'San Antonio' OR location = 'Austin')"

Now on to the question. I had implemeted a routine in several scripts to handle SQL insertions and updates automatically by parsing out the keys and values from CGI. Becasue of this I began toying with the object oriented functionality of CGI.pm. This would allow me to assign the CGI params and values to a hash(%IN) and A)do a 'delete $IN{submit};' or $IN{myparam} = $someval and B)not have to assign my 30 or so params using my $param = param("someparam") either with global scope or passing many of them to several subroutines.

I am able to get the Object Orinted functionality working using the following code:
use strict; use CGI; my ($cgi, $key, %IN); $cgi = new CGI; %IN = $cgi->Vars; #%IN = (param1 => value1, param2 => value2 , etc..);
Though I am having issues attempting to handle multiple selects. See the code below for a failed example.
if (defined $IN{location}) { $where .= "AND (location = '$IN{location}[0]'"; for my $i (@{$IN{location}}) { $where .= "$i" }; $where = "$where)"; }
Below is an example of one of my insert routines from my other scripts.

delete $IN{somekey}; delete $IN{somekey1}; delete $IN{somekey2}; delete $IN{somekey3}; $IN{somekey4} = "someval"; foreach $key (keys %IN) { $keys[$i] = $key; $value = $IN{$key}; $value = $dbh->quote($value); #removes quotes from the values $values[$i] = $value; $i++; } my $key_string = join(',',@keys); #joins array elements, and status a +nd adds a comma my $value_string = join(',',@values"); #joins array values, and stat +us, and adds a comma $sql = "$function $tablename ($key_string) values ($value_string)"; $sth = $dbh->prepare($sql); $sth->execute();

Now to end my rambling and ask the question.
What is the best way to handle the CGI from a form with a large amount of elements and with multiple selects? Should I use the object oriented functionality? If so how do I handle multiple selects?

Thanks in advance,
Weary hok_si_la

In reply to CGI.pm OO vs. FO by hok_si_la

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.