Hey all, Poured over a number of texts online and having trouble easily converting a mass quantity of existing code to work well under mod_perl in an easy-to-manage method.
Currently, we have a few MB of unique Perl scripts running various web applications, and I'm having trouble scoping when requiring those scripts in our main application. We have a 'base' script, which I'll call webapp.pl, which requires a number of other scripts, including a script that loads up a number of cursors for our database at startup so they don't get prepared over and over and over. The scoping of the cursor names is giving me grief though: webapp.pl --- #!/usr/bin/perl use strict; use vars qw( $dbh $cursor1 $cursor2 $cursor3 etc $cursor250 ) ; require ("mysql.pl") ; ## has sub's to connect/disconnect to mysql require ("cursors.pl") ; ## example printed below &connect_to_mysql() ; ## defined in mysql.pl &declare_cursors() ; ## defined in cursors.pl (see below) # do work here &finish_cursors() ; ## defined in cursors.pl (see below) &disconnect_from_mysql() ; ## defined in mysql.pl exit ; cursors.pl --- use vars qw( $dbh $cursor1 $cursor2 $cursor3 etc ad nauseum $cursor250 ) ; sub declare_cursors { $cursor1 = $dbh->prepare ("SELECT something FROM something WHERE something=?") ; etc $cursor250 = ... } sub finish_cursors { $cursor1->finish ; etc } The problem I'm having is that the 'use vars' from the top of cursors.pl doesn't give webapp.pl scope of its variables, so I have to redefine the entire list of cursors in all of the scripts we have if the script uses any of the cursors defined in cursors.pl, which is a nuisance if I need to remove or edit a cursor's name... I end up with dozens of places to change the cursor name or remove a cursor. Is there an easier way to manage this? It's not just with this cursors.pl script either - we'd like to define other Perl scripts with their own global variables that can build those variables for global scope simple by requiring the script, but haven't seen anything yet to accomplish this. Another example would be for webapp.pl to require our "cookies.pl" code that looks like this: cookies.pl ----- use vars qw( %COOKIES ) ; sub getallcookies() { my %mycookies ; # etc etc, parse what the browser gives us return %mycookies ; } In order to make this call within webapp.pl: %COOKIES = &getallcookies() ; ... we have to define %COOKIES all over again. Thanks for any assistance. Ian Douglas -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html