in reply to Re: how to get alias name of anonymous sub? (closure)
in thread how to get alias name of anonymous sub?

Thanks tye .But it seem there is some problem in your solution ,the variable will be assigned according the context where the sub be executed.just like this.
package test; for (A..D) { *{$_}=sub{ print "my name is $_ \n"; }; } package main; test->A(); test->B(); $_="here"; test->C(); test->D(); output: my name is my name is my name is here my name is here

Replies are listed 'Best First'.
Re^3: how to get alias name of anonymous sub? (closure)
by tye (Sage) on Nov 29, 2010 at 08:04 UTC

    No, that is a problem with your code. Closures close over lexicals. $_ is not a lexical. You deleted a line that I inserted quite intentionally and thus broke the code.

    - tye