Re: So bewilderingly. about closure

2007-09-20 Thread Joshua ben Jore
On 9/20/07, demerphq <[EMAIL PROTECTED]> wrote: > The solution is to add a dummy line to f() to make sure that it mentions $x. > > { > my $x = 'A'; > sub f { my $y=$x; sub { print \$x; $x++ } } > sub g { sub { print \$x; $x++ } if $x } > } My experience was just a void

Re: So bewilderingly. about closure

2007-09-20 Thread Dave Mitchell
On Thu, Sep 20, 2007 at 11:48:15AM +0200, demerphq wrote: > On 9/20/07, flw <[EMAIL PROTECTED]> wrote: > > C:\>cat ttt.pl > > use strict; > > use warnings; > > > > { > > my $x = 'A'; > > sub f { sub { $x++ } } > > sub g { sub { $x++ } if $x } > > } > > > > my $F=f(); > > my $G=g(); > >

So bewilderingly. about closure

2007-09-20 Thread flw
C:\>cat ttt.pl use strict; use warnings; { my $x = 'A'; sub f { sub { $x++ } } sub g { sub { $x++ } if $x } } my $F=f(); my $G=g(); print $F->(),$G->(),"," for 1..4; print "\n"; C:\>ttt.pl 0A,1B,2C,3D, C:\>

Re: So bewilderingly. about closure

2007-09-20 Thread demerphq
On 9/20/07, flw <[EMAIL PROTECTED]> wrote: > C:\>cat ttt.pl > use strict; > use warnings; > > { > my $x = 'A'; > sub f { sub { $x++ } } > sub g { sub { $x++ } if $x } > } > > my $F=f(); > my $G=g(); > > print $F->(),$G->(),"," for 1..4; > print "\n"; > > C:\>ttt.pl > 0A,1B,2C,3D, > > C: