Problems? Is your data what you think it is? | |
PerlMonks |
Setting lexicals in a BEGIN block.by mephit (Scribe) |
on Jun 20, 2002 at 22:04 UTC ( [id://176172]=perlquestion: print w/replies, xml ) | Need Help?? |
mephit has asked for the wisdom of the Perl Monks concerning the following question:
Greetings. Quick background: I want to use a module if it exists, otherwise use another, then create a file-scoped lexical object of the appropriate class. This would best be done in a BEGIN block, I've figured out. After a few Super Searches, I figured out a few ways to set a file-scoped variable within said BEGIN block, and I'm wondering which is the Best Way, or if it's just a matter of programmer preference. I have all methods incorporated in the code snippet below, so I wouldn't have to illustrate things four times. They all work, except for the $our_var method. I find this odd, since a "use vars" variable works, but "our" doesn't. Aren't the two the same thing? Thanks to tye and this node for pointing out that a 'my' var declared before a BEGIN block won't cause problems. I assumed that it wouldn't work, but it does. Yay. Anyway, here's my code: So, which is best? Is that even a real closure? And why doesn't the $our_var method work? Thanks for any help, folks. Mephit -- There are 10 kinds of people -- those that understand binary, and those that don't.
Back to
Seekers of Perl Wisdom
|
|