A while ago, I posted some inconsistencies with scope declarators.
(http:[EMAIL PROTECTED]/msg08028.html)
A few more related notions....
----
$a = "test";
{
chop(my $a = our $a = "hello");
# The lexical is chopped....
print "1-$a\n";
# But the global is printed
}
print "2-$a\n";
# The assignments are evaluated right-to-left, resulting in the lexical
# being chomped. But the rightmost declaration is the one propogated
# through the rest of the scope.
----
$b = "test";
{
chop($b = my $b = "hello");
# The global is chopped....
print "1-$b\n";
# But the lexical is printed
}
print "2-$b\n";
# This one makes sense. The lexical is created and initialized with
# "hello". That value is then passed to whatever the current $b in
# use is - the global (by default). The lexical doesn't come fully into
# view until the next statement.
----
$c = "test";
{
chop(our $c = my $c = "hello");
# Bizarre warning... but the global is chopped.
print "1-$c\n";
# The lexical is printed
}
print "2-$c\n";
# Here, Perl recognizes that there were two variable declarations,
# (since 'our' currently affects all subsequent variables on the same line)
# The global is still chopped, because it was the last one assigned, but
# the lexical takes affect, since it was the last one (in left-to-right
# order) declared.
----
Obviously, this is most heinous code to write. And except for problems
centered around when the declarations take affect, it warns appropriately.
'our' is a true accessor, meaning you can query the value, or you can set it.
'my' and 'local' aren't. They set the value to 'undef' or the value you
pass in. (Perhaps it'd be easier to think of it as 'our $a =
$__PACKAGE__::a')
In either case, that means an assignment is ultimately involved.
Assignments are handled right-to-left, so I think the scope declarators
should be too. (Once all the other problems are fixed.)
--
Bryan C. Warnock
[EMAIL PROTECTED]