On Tue, 23 May 2000, Marc Lehmann wrote:
> At leats in the example I sent in there is no sign of any closure.

There is a closure, and this might be the thing that's making trouble for
you, or at least part of it.  This is a closure:

> package othermodule;
> my $global = 5;
> 
> sub set_global {
>   $global = shift;
> }

That will cause &set_global to keep a copy of $global after it goes out of
scope for the rest of the package.

> Indeed, I could have worded it better. Just replace global by
> "file-scope" and it is correct, though. What I wanted to make clear is
> that the my variable in question is global (= life during the program
> lifetime), since it was declared at package scope.

A lexical (my) variable normally goes away when perl leaves the scope it
was declared in.  Only your closure kept it around.

> Huh? Why is "do" a bad thing????

Do is bad because it is called every time, even if you've already executed
the code, unlike require which checks %INC.  It also makes you check $@ to
see if the code compiled, unlike require.  It's usually used for nasty
perl4-ish stuff without packages.  In your case, you're setting your own
flag to keep from compiling again and checking $@ yourself, so you're
getting around these problems, but the file form of do is generally a red
flag.

- Perrin

Reply via email to