http://www.perlmonks.org?node_id=490747


in reply to CGI.pm OO vs. FO

I'd use OO when your going to need to call multiple params at different times/different lexical scopes (the creation of a global cgi variable to control when and where you need certain params), something like the code that follows:

use CGI; my $cgi = $cgi->new; sqlstuff(); email_someone(); sub sqlstuff { my @locations = $cgi->param('locations'); my $sql = q(select * from table where server like '%someserver%' and + ); $sql .= sprintf "(%s)", join " or ", map { location='$_'" } @locatio +ns; #thanks to [blokhead] for the above #see below for explaination #if needed in existing %IN hash (with assuming other fields) $IN{location} = [ @locations ]; .... do stuff ... } sub email_someone { my $someone = $cgi->params('someone'); .... do emailing stuff here ... }

There are other ways to do this, but having seen your whole script this looks like a good stepping point.

As for your actually code Vars returns a hash while param returns an array (or scalar depending on how it's called) so if you use $cgi->Vars you should use $where .= "$_" for values %IN; (if you have multiple locations from checkboxes you want param as Vars will combine locations into a single string)

Update: Replied to CB questions and sql creation explaination:
sprintf "(%s)" : meaning insert string between ()
join " or " : returns a joined string (using delimiter "\sor\s" for inserting
map { location ='$_'"} @locations; : sets location='$location[0]..[$#location] as the array for join to join

"Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce