in reply to Setting lexicals in a BEGIN block.

get_obj() is a closure. Variables declared with 'our' are lexically scoped:
use warnings; use strict; { our $foo = 1; } print $foo;

Replies are listed 'Best First'.
Re: Re: Setting lexicals in a BEGIN block.
by Juerd (Abbot) on Jun 21, 2002 at 07:04 UTC

    Variables declared with 'our' are lexically scoped:

    Only their declaration is lexically scoped. The variable itself is a real global.

    use strict; use warnings; { our $foo = "Hello, world!\n"; } { print our $foo; # prints: Hello, world! }
    Only "my" variables are real lexicals:
    use strict; use warnings; { my $foo = "Hello, world!\n"; } { print my $foo; # warns: Use of uninitialized value }

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.