in reply to Re^7: what is difference between calling the function in Perl/Tk in the following ways
in thread what is difference between calling the function in Perl/Tk in the following ways

There's no function in there, so it supports what I guessed: It's got nothing to do with closures.

Another danger of the non-list approach is that the function sees the lexical context of its definition and can accidentally use something from there

No, they don't accidentally capture anything. Closures only capture the variables they need.

The following shows that $x wasn't captured even though it was visible to the capture.

use strict; use warnings; printf "x=%s\n", do { my $x = 2; sub { $x } }->() // 'undef'; printf "x=%s\n", do { my $x = 2; sub { eval '$x' } }->() // 'undef';
x=2 Variable "$x" is not available at (eval 1) line 2. x=undef

The warning is new, but the behaviour is ancient.

  • Comment on Re^8: what is difference between calling the function in Perl/Tk in the following ways
  • Select or Download Code

Replies are listed 'Best First'.
Re^9: what is difference between calling the function in Perl/Tk in the following ways
by choroba (Cardinal) on Apr 18, 2010 at 18:06 UTC
    I perhaps do not use English conjunctions (or other words) in the right way, for which I apologize. But by accidental leaking I meant an error made by the programmer (like missing "my" inside of the annonymous sub), not by perl. And the example of the behaviour of Button was given to show why I am no longer able to reproduce the tests we did.