develooper Front page | perl.perl5.porters | Postings from March 2000

bug or not ?

Thread Next
From:
Graham Barr
Date:
March 17, 2000 09:55
Subject:
bug or not ?
Message ID:
20000317175349.U7192@pobox.com
I am not sure if this is a bug or not.

my $x = 1;
$clo = sub { print "closure ",$x,"\n"; };
for $x (qw(a b)) {
  print "for ",$x,"\n";
  &$clo;
}

gives

for a
closure 1
for b
closure 1

which  is what I would expect if there was a my in the for statement.
However if $x is a package variable, you get

for a
closure a
for b
closure b


Graham.


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