From hempy at ket.org Mon May 21 21:23:04 2001 From: hempy at ket.org (David Hempy) Date: Thu Aug 5 00:06:06 2004 Subject: LPM: Packages and persistence. Message-ID: <5.0.0.25.0.20010521220733.01f05d00@mail.ket.org> Okay...I'm migrating a system into PerlEX (ActiveState's answer to modPerl), and seeing some nifty performance increases. I'm running into a little bit of unwanted variable persistence. For the most part, I'm okay because I always use strict and initialize my variables. However, I use some explicit package variable in conjunction with Text::Template. For example, $TEMPLATE::table_rows .= "..."; I started to initialize all these variable at the start of each invocation, which would work just fine. Problem is, I don't trust myself to catch them all. Plus, they'll be hanging around taking up memory in the meantime, and a particularly bad memory leak situation if I continually append to the variable. Soooo.... What I want to do is systematically initialize all the variables in a package at startup. (I guess at shutdown would be even better.) I've got it pretty well licked by messing around in the symbol table. The following code demonstrates this. The juicy part is in PurgePackage(), which is lifted largely from the Camel book's package chapter. $hello='FROM MAIN'; $TEMPLATE::hello='FROM TEMPLATE'; $TEMPLATE::now='then'; DumpPackage('main::TEMPLATE::'); PurgePackage('main::TEMPLATE::'); DumpPackage('main::TEMPLATE::'); sub DumpPackage { ($pkg) = @_; print "package: $pkg\n"; foreach $var (sort keys %{$pkg}) { $var = "$pkg$var"; print " \$$var -> " . ${$var} . "\n"; } print "\n"; } sub PurgePackage { ($pkg) = @_; print "package: $pkg\n"; foreach $var (sort keys %{$pkg}) { $var = "$pkg$var"; print " undef \$$var\n"; undef $$var; } print "undef \$$pkg\n"; undef $$pkg; print "\n"; } Running this yields: package: main::TEMPLATE:: $main::TEMPLATE::hello -> FROM TEMPLATE $main::TEMPLATE::now -> then package: main::TEMPLATE:: undef $main::TEMPLATE::hello undef $main::TEMPLATE::now undef $main::TEMPLATE:: package: main::TEMPLATE:: $main::TEMPLATE::hello -> $main::TEMPLATE::now -> I'm happy that the values of each variable get wiped out, but a bit surprised that they still exist at all. Doesn't undef pretty much wipe a variable out of existance? Am I missing a concept about variables and symbol tables? On a larger scale, am I missing the big picture? Only after finishing the previous paragraph did I return back to the Text::Template docs, and now I'm wondering if a hash would work better than a package for persistence issues. With a hash, I could just undef the whole thing or let it go out of scope without a problem. Any thoughts from folks who have had similar adventures with modPerl or PerlEX? -dave -- David Hempy Internet Database Administrator Kentucky Educational Television - Distance Learning Division -- (859)258-7164 -- (800)333-9764 From rbowen at rcbowen.com Tue May 22 11:18:19 2001 From: rbowen at rcbowen.com (Rich Bowen) Date: Thu Aug 5 00:06:06 2004 Subject: LPM: Hmm. Meeting? Message-ID: <200105221618.f4MGIMQ09146@rhiannon.rcbowen.com> Next month (June) I'll be gone to YAPC for a week, and in DC part of the next week, so it seems moderately unlikely that I'll be able to pull together a meeting for June. Not that the last one was a roaring success. Is anyone interested enough in having a meeting to do the legwork to get a place and time that people can agree on? I'm getting a little tired of the monthly struggle to find a meeting time, and then having 3 people show up. -- Rich Bowen - rbowen@rcbowen.com .. and another brother out of his mind, and another brother out at New York (not the same, though it might appear so) Somebody's Luggage (Charles Dickens)