I'm working on a somewhat complex application that uses CGI, CGI::Session and DBI. I've been following a practice of having no globals and passing variables to every subroutine that I have because this served me well in the past. However, I'm running into the problem that I'm passing 5-6 variables to each subroutine, and what's worse, sometimes that particular subroutine doesn't even need the variables, except to pass to another subroutine (!).</p.
So for example:
MAIN: { my $cgi = CGI->new(); my $session = CGI::Session->new(...); my $dbh = $dbh->connect(...); my $result = do_something($cgi, $session, $dbh); print $cgi->header().$result; } sub do_something { my ($cgi, $session, $dbh) = @_; $dbh->foo(...); $cgi->bar(...); my $foo = another_subroutine($cgi, $dbh, $somevar, $othervar); return final_result ($cgi, $session, $foo); } sub another_subroutine { my ($cgi, $dbh, $somevar, $othervar) = @_; return $dbh->baz($cgi, $somevar, $othervar); } sub final_result { my ($cgi, $session, $foo) = @_; my $result = # operations with $cgi, $session and $foo return $result; }
Basically, you get the idea. I'm probably doing something wrong when it comes to the actual flow of the program, but I have no idea what or where to start. Maybe what I'm really asking for are tips on designing perl CGI applications?
In reply to Best practices passing database handles, cgi objects, etc. by xtpu2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |