Front page | perl.perl6.language |
Postings from November 2002
Re: on Topic
Thread Previous
|
Thread Next
From:
Larry Wall
Date:
November 13, 2002 11:22
Subject:
Re: on Topic
Message ID:
20021113192150.GC14308@wall.org
On Wed, Nov 13, 2002 at 03:11:32PM +0200, fearcadi@figaro.weizmann.ac.il wrote:
: so if I understand correctly ,
:
: Every topicalizer defines a topicalizer scope in which there is
: implicit declaration
:
: my $_ ;
:
: and then lexical $_ ( implicitely ) is bound to ( or assigned to )
: whatever it should in this particular topicalizer. And from that on $_
: is just another lexical variable .
Yes.
: Question(s) :
:
: with no "use strict vars" any "just another variable" is taken by perl as
: being global -- it is implicitly "our $just_another_var;" (???)
: about any lexical veriable ( just_another_variable ) Perl have to be
: explicitly informed as being such . is $_ just_another_variable in
: that respect too ???
$_ is always a lexical. Every file scope has an implicit "my $_" at the top.
Every nested scope either sets up its own lexical $_ or aliases to an outer $_.
: in other words , what happens if I just use $_ ( that is , without
: previous declaration ) *outside any topicalizer* ?
There is no "outside any topicalizer" from that standpoint. However,
$_ does start off undefined in an implicit topicalizer, and we may
well disallow "break" to such an implicit topicalizer at file scope,
and maybe at subroutine scope.
: * will it be implicitly "our $_" ( probably not , because it is
: always lexical )
Correct, $_ is always lexical. But...
: or * will it be implicitely "my $_" -- class/package lexical
There's no such thing as a "class/package lexical". I think you
mean file-scoped lexical here.
: or * will it be error to just use it without declaration
: * with "use strict vars"
: * with "no strict vars "
:
: will it be an error to declare it as "our $_" ;
No, in this case, $_ is still considered a lexical, but it just happens
to be aliased to a variable in the current package.
: and to repeat the question from previous post ,
: what will perl do when it see
:
: $My_Package::_ = 1 ;
It'll set the $My_Package::_ variable to 1, I presume. Whether that
has any influence on the value of $_ depends on how $_ is currently
aliased. But the name $_ will always be interpreted according to the
lexical definitions set up by "my" and "our" (including the implicit
outer "my").
Larry
Thread Previous
|
Thread Next