vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

sub Create_fun { my ($var) = @_; sub { print "$var";} } $anony_sub_ref = Create_fun("first_function");

In the above code the function Create_fun() return the reference to anonymous function and the $anony_sub_ref holds it I need to give name to this anonymous function How can I do it ?

Vinoth,G

Replies are listed 'Best First'.
Re: Giving name to anonymous function
by moritz (Cardinal) on Apr 22, 2009 at 08:58 UTC
    *subname = $sub_ref;. Search for glob in perldata for more details.
      That will give a name by which the function may be called. It will not make caller give the function a clear name. If you want the latter, SubName is your friend. You can also accomplish the same thing by having local *__ANON__ = "$package\::$function"; in your function. (SubName is clearer.)
Re: Giving name to anonymous function
by Anonymous Monk on Apr 22, 2009 at 10:14 UTC
    Where did you copy that question from?

      Why you people also want to copy from there ?

      Actually, that was my first thought too.


      holli

      When you're up to your ass in alligators, it's difficult to remember that your original purpose was to drain the swamp.