develooper Front page | perl.perl5.porters | Postings from October 2003

RE: [perl #24250] "return" required in some anonymous closures

Thread Previous | Thread Next
From:
Elizabeth Mattijsen
Date:
October 20, 2003 06:15
Subject:
RE: [perl #24250] "return" required in some anonymous closures
Message ID:
p05111b08bbb98f952271@[192.168.56.2]
At 13:59 +0100 10/20/03, Orton, Yves wrote:
>  > At 13:34 +0100 10/20/03, Nick Ing-Simmons wrote:
>>  >  >so this looks like an optimizer problem to me: the $get sub is
>>  >  >referring to something else than the package lexical $foo.
>>  >What is a 'package lexical' ?
>>  >   - things are either in package or lexical never both...
>>
>  > A package lexical is a lexical defined at the package "scope"?
>Except that there is no such thing as package scope. There is file scope and
>block scope, nothing else.
>
>#!perl -l
>package foo;
>my $bar="hello";
>print $bar;
>package main;
>print $bar;
>
>__END__
>hello
>hello

Or alternately:

use strict;
use warnings;

package Foo;
my $foo = 1;

package Bar;
my $foo = 2;
__END__
"my" variable $foo masks earlier declaration in same scope at line 8.

I see your point.


>  > package Foo;
>  > my $package_lexical;
>  > {
>  >   my $not_a_package_lexical;
>  > }
>  > I thought that was a pretty well known concept?
>Well, I think its a pretty well known misnomer. But it still is a misnomer.
>$package_lexical should actually be called $file_lexical.
>
>If you want a "package lexical" youll have to wrap the whole thing in a
>block.
>
>package foo;
>{
>   my $package_foo_lexical;
>}
>
>or
>
>{
>   package foo;
>   my $package_foo_lexical;
>}
>
>Personally I like the first one more....

{
  package Foo;
  print __PACKAGE__,$/;
}
print __PACKAGE__,$/;
__END__
Foo
main


See, packages are scoped!  ;-)   Just kidding.  I will now start to 
reprogram myself to use "file lexical" rather than "package lexical".


Liz

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About