Curious About Require
Hello, I have a question about require when using mod-perl. I produced four simple .pl files. main.pl, one.pl two.pl three.pl From the main.pl you can link to either one two or three.pl. Pretty simple. The problem begins when I put a require in one.pl, two.pl, and three.pl. If in each of those files I put in for instance: require D:/Apache/mod_perl/query.pl; When I click on the main, and lets say I go to one.pl it works fine. If I then proceed to click on two.pl (it says query.pl not found), even though there is a require. Restart Apache, Then click from main to two.pl it works fine. If then I go to one.pl error (it says query.pl not found). So my question is why this bazaar behavior. If I change the query.pl to a module and use it in each of the pages it is fine. I just find this behavior rather funny. If anyone has any insight please update me. Thanks, Scott Purcell
Re: Curious About Require
Greetings, require will only happen once per perl process and since mod_perl is essentially a single perl process, the file is only require'd for the first request. You can get around this by deleting the file from the %INC hash which keeps track of which files you have loaded. Something like: BEGIN { delete $INC{'/foo/bar/query.pl'} if exists $INC{'/foo/bar/query.pl'}; require '/foo/bar/query.pl'; } Cheers, Mark On Wednesday, June 20, 2001, at 10:04 AM, Purcell, Scott wrote: Hello, I have a question about require when using mod-perl. I produced four simple .pl files. main.pl, one.pl two.pl three.pl So my question is why this bazaar behavior. If I change the query.pl to a module and use it in each of the pages it is fine. I just find this behavior rather funny. If anyone has any insight please update me. Thanks, Scott Purcell
Re: Curious About Require
On Wed, 20 Jun 2001, Mark Doyle wrote: Greetings, require will only happen once per perl process and since mod_perl is essentially a single perl process, the file is only require'd for the first request. You can get around this by deleting the file from the %INC hash which keeps track of which files you have loaded. Something like: BEGIN { delete $INC{'/foo/bar/query.pl'} if exists $INC{'/foo/bar/query.pl'}; require '/foo/bar/query.pl'; } Mark, your suggestion doesn't work because of BEGIN. See the URL posted in my other reply for the explanation. Cheers, Mark On Wednesday, June 20, 2001, at 10:04 AM, Purcell, Scott wrote: Hello, I have a question about require when using mod-perl. I produced four simple .pl files. main.pl, one.pl two.pl three.pl So my question is why this bazaar behavior. If I change the query.pl to a module and use it in each of the pages it is fine. I just find this behavior rather funny. If anyone has any insight please update me. Thanks, Scott Purcell _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/ http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: Curious About Require
On Thu, 21 Jun 2001, Stas Bekman wrote: On Wed, 20 Jun 2001, Mark Doyle wrote: Greetings, require will only happen once per perl process and since mod_perl is essentially a single perl process, the file is only require'd for the first request. You can get around this by deleting the file from the %INC hash which keeps track of which files you have loaded. Something like: BEGIN { delete $INC{'/foo/bar/query.pl'} if exists $INC{'/foo/bar/query.pl'}; require '/foo/bar/query.pl'; } Mark, your suggestion doesn't work because of BEGIN. Ooops, gotta go to sleep. Your suggestion, Mark, will work :) but only in Registry/PerlRun which executes BEGIN on every request. Sorry about my previous post :( But if you delete and reload the file on every request it defeats the purpose of using mod_perl to some degree, depending on how many files you force to reload and how big they are. BTW, here is shorter version of your suggestion: BEGIN { do '/foo/bar/query.pl'; } See the URL posted in my other reply for the explanation. Still holds :) Cheers, Mark On Wednesday, June 20, 2001, at 10:04 AM, Purcell, Scott wrote: Hello, I have a question about require when using mod-perl. I produced four simple .pl files. main.pl, one.pl two.pl three.pl So my question is why this bazaar behavior. If I change the query.pl to a module and use it in each of the pages it is fine. I just find this behavior rather funny. If anyone has any insight please update me. Thanks, Scott Purcell _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/ http://singlesheaven.com http://perl.apache.org http://perlmonth.com/ _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/ http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: Curious About Require
BEGIN { delete $INC{'/foo/bar/query.pl'} if exists $INC{'/foo/bar/query.pl'}; require '/foo/bar/query.pl'; } Mark, your suggestion doesn't work because of BEGIN. Ooops, gotta go to sleep. Your suggestion, Mark, will work :) but only in Registry/PerlRun which executes BEGIN on every request. It only needs to do the require once per script, so if you put this in each script it will be fine. Also, I don't think Registry runs BEGIN blocks every time. Can't remember about PerlRun. BTW, here is shorter version of your suggestion: BEGIN { do '/foo/bar/query.pl'; } That's what I used when porting someone's old perl4-ish code to PerlRun. Both of these quick fixes waste memory though. - Perrin
Re: Curious About Require
Greetings, On Wednesday, June 20, 2001, at 12:45 PM, Stas Bekman wrote: Ooops, gotta go to sleep. Your suggestion, Mark, will work :) but only in Registry/PerlRun which executes BEGIN on every request. Sorry about my previous post :( But if you delete and reload the file on every request it defeats the purpose of using mod_perl to some degree, depending on how many files you force to reload and how big they are. BTW, here is shorter version of your suggestion: BEGIN { do '/foo/bar/query.pl'; } Sorry, I guess I should have been more explicit. I don't want to require in the file on every request, but rather only allow the same file to be require'd multiple times (to install the same sub routines into different packages). This is needed because we have modularized some of our XML handlers for SUBS-style parsing in XML::Parser and we need create multiple subclasses of XML::Parser that share the same modularized components. The packages that subclass XML::Parser are read in only once in the startup.pl file. The last require leaves the files in the %INC hash, so it isn't subsequently read in on every request (so 'do' isn't quite the same). Cheers, Mark
Re: Curious About Require
I hate to belabor this point, but I don't want people to get the wrong idea: BEGIN { do '/foo/bar/query.pl'; } Sorry, I guess I should have been more explicit. I don't want to require in the file on every request, but rather only allow the same file to be require'd multiple times (to install the same sub routines into different packages). That's what this accomplishes. It only runs once, being inside of a BEGIN block. Using do() instead of require() skips the %INC check, so you don't have to delete anything from %INC this way. Of course, do() doesn't check to see if your module returned true, but they are basically equivalent. TMTOWTDI. - Perrin