in reply to 'our' scoping

'our' is just a lexically-scoped compiler directive altering the behviour of 'use strict' for a global variable. The variable is still accessible from all all parts of a program, but within the scope of the 'our' declaration, it is immune from the ravages of 'use strict', eg
$foo = 1; use strict; { our $foo; $foo++; # $::foo now 2 } { no strict; $foo++; # $::foo now 3 } # dies with # Global symbol "$foo" requires explicit package name $foo++;

Dave.

Replies are listed 'Best First'.
Re: Re: 'our' scoping
by tilly (Archbishop) on Jun 01, 2004 at 23:37 UTC
    Your description of how our works is subtly wrong. The following demonstrates this, without any strict in the way.
    package foo; our $foo = "I'm in foo"; package bar; our $foo = "I'm in bar"; package foo; print "1) $foo\n2) $foo::foo\n3) $bar::foo\n";
    Note that our caused you to access $bar::foo even when you'd have otherwise expected to access $foo::foo.

    For giggles and grins, mix our with $_ when you aren't in package main. Tons of confusion!