in reply to Re: Setting lexicals in a BEGIN block.
in thread Setting lexicals in a BEGIN block.

The vars pragma is not block-scoped, but file scoped

In fact, the documentation is a little off on that one. The vars pragma is neither block nor file scoped, it is package scoped.

  • Comment on Re: Re: Setting lexicals in a BEGIN block.

Replies are listed 'Best First'.
Re: Setting lexicals in a BEGIN block.
by Abigail-II (Bishop) on Jun 21, 2002 at 09:25 UTC
    It's better to say that it isn't scoped at all. All the vars pragma does is, after some checking of arguments, is using the fully qualified variable in a dummy statement. There is no scoping involved.

    Abigail

      By package scoped I mean that unqualified use of a variable declared with use vars qw($foo) follows package boundaries: 1) unqualified use of $foo is not allowed inside another package (even in the same file as the declaration), and 2) unqualified use of $foo is allowed anywhere within the same package (even in different files from the declaration).