in reply to Re^2: Logic for importing and strict vars?
in thread Logic for importing and strict vars?
While experimenting with this code I stepped away from using $a, main and one-liners and I can report to you that the results are exactly the same:
package Foo ; use strict ; our $t = 2 ; { BEGIN { # package Bar ; # added *Foo::x = \$Foo::t; } ++$x ; # ++$Foo::x; # no errors print $x ; # print $Foo::x; # no errors }
Small note regards the Deparse results: With 'package Bar' disabled it looks like *Foo::x = \$Foo::t; becomes: *x = \$t; and with 'package Bar' enabled it becomes: *Foo::x = \$Foo::t;. Inside the BEGIN statement I think it is likely that the first form is not a valid trigger to 'declare' $x and the latter form is valid, but the reason could also be what tye said regards: "when the variable slot of a glob gets assigned to by code compiled into another package". But I am still confused though 'what' declared means. Is it turned into a lexical scoped package variable, or is it similar to 'use vars'?. This line in 'use' documentation is not clear to me:"...which are effective through the end of the file..." in the text: "Some of these pseudo-modules import semantics into the current block scope (like strict or integer , unlike ordinary modules, which import symbols into the current package (which are effective through the end of the file)".
In case you do wish to use this as a one-liner (Windows):
perl -MO=Deparse -wMstrict -e "package Foo ; our $t = 2 ; { BEGIN { package Bar { *Foo::x=\$Foo::t } } ; ++$x ; print $x }"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Logic for importing and strict vars?
by haukex (Archbishop) on Feb 28, 2019 at 22:24 UTC |