in reply to Our, use vars, and magic, oh my!

The only thing that bothers me is that we have at the same time :
I have no problem with the first point (I've checked it several times).

But I thought that lexically scoped vars couldn't be accessed from the outside
beccause they weren't in the package's namespace (but were in a 'scratchpad').

Did I wrongly assume that 'lexically scoped' implied the use of a 'scratchpad'
(was it rather 'my var' implies use of scratchpad)
or does it mean that despite being lexically scoped a 'our' variable is also 'exported' in the namespace ?

Anyone to clear this point ?


"Only Bad Coders Code Badly In Perl" (OBC2BIP)

Replies are listed 'Best First'.
Re: Re: Our, use vars, and magic, oh my!
by arturo (Vicar) on Aug 23, 2001 at 18:14 UTC

    The fact that a variable is lexically scoped doesn't imply anything about the internal implementation. Lexical scoping is more a matter of syntax than anything else.

    According to the man page perlfunc:our or perldoc -f our, you can see that what the package Foo; our $foo; declaration does is get the interpreter to see occurrences of $foo unadorned, as it were, as occurrences of $Foo::foo, so it's a plain ol' package global:

    An "our" declaration declares a global variable that will be visible across its entire lexical scope, even across package boundaries. The package in which the variable is entered is determined at the point of the declaration, not at the point of use.

    HTH

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'