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

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

From:
Elizabeth Mattijsen
Date:
October 20, 2003 02:45
Subject:
Re: [perl #24250] "return" required in some anonymous closures
Message ID:
p05111b02bbb95e629a0a@[192.168.56.2]
At 23:01 +0000 10/19/03, martin@suttles.sca.sfbay.sun.com (via RT) wrote:
># New Ticket Created by  martin@suttles.sca.sfbay.sun.com
># Please include the string:  [perl #24250]
># in the subject line of all future correspondence about this issue.
># <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24250 >
>
>
>
>This is a bug report for perl from martin@suttles.sca.sfbay.sun.com,
>generated with the help of perlbug 1.34 running under perl v5.8.1.
>
>
>-----------------------------------------------------------------
>[Please enter your report here]
>Consider the following perl program
>
>my $count = 0;
>my $x = [sub() { $count },
>	 sub() { return $count },
>	 sub($) { $count += $_[0] }];
>$x->[2](3);
>printf "%d %d\n", $x->[0](), $x->[1]();
>
>This prints
>0 3
>when it should print
>3 3

Confirmed.

Please note that if you change:

   my $count = 0;

to:

   our $count = 0;

the result as is expected.  So this would imply a lexical pad problem to me.


Furthermore, if you change:

   my $count = 0;

to:

   my $count = 'Foo';

the result is _still_:

0 3

which indicates to me the "0" is gotten from somewhere else, rather 
than from $count.


Liz



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