* Father Chrysostomos via RT <perlbug-comment@perl.org> [2012-10-16 23:50]: > So that means state(our @foo) = ... should assign to the package > variable @foo once. > > Right? $ perl -E'my (our $foo) = 1; say $::foo ? 1 : 0' 1 $ perl -E'our (my $foo) = 1; say $::foo ? 1 : 0' 0 To my mind that is a “no”. So far `state` is basically just another declarator, which in Perl can be strewn throughout an expression, and the closest declarator wins. But it’s already not quite just another declarator, but one with some special behaviour. That’s fine but I don’t think I want its semantics complicated further so that it becomes kind of a declarator with some special behaviour that also modifies some other declarators within the expression. (Maybe it is a missed opportunity that isn’t spelled `state my`. I care not to tug that ship back into the port now by the anchor line though.) For those times where you really need this functionality you might be able to just abuse lexical `state`: { state $init = do { our $foo = 1 } } Not as obvious as I would like, but at least not ugly either. And with the aid of Devel::CallSite you can sugar it up to the point of stately { our $foo = 1 }; -- *AUTOLOAD=*_;sub _{s/::([^:]*)$/print$1,(",$\/"," ")[defined wantarray]/e;chop;$_} &Just->another->Perl->hack; #Aristotle Pagaltzis // <http://plasmasturm.org/>Thread Previous | Thread Next